Skip to content

Operation with native integer constant that might overflow in unchecked context should be treated as not constant #45531

@cston

Description

@cston

The value of y depends on whether the program is executed on 32-bit or 64-bit platform. Therefore the value should be treated as non-constant. See LDM-2020-03-25.

using System;

class Program
{
    static void Main()
    {
        const long x = 0xFFFFFFFFFFFFFFFL;
        const nint y = unchecked((nint)x);
              nint z = unchecked((nint)x);
        Console.WriteLine("{0}, {1}", y, z);
    }
}

Expected: error CS0133: The expression being assigned to 'y' must be constant
Actual: No errors

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions