False-negative for S2183 in enum values

  • Language: C#
  • Rule: S2183
  • Product: SonarQube for Visual Studio 8.11.0.11944
  • IDE: Visual Studio Community 2022 17.12.4
  • Connected mode: No

The rule S2183 (“Integral numbers should not be shifted by zero or more than their number of bits-1”) doesn’t trigger for the values in enum types when shifting by the number of bits or more. For example:

internal static class Program
{
    static void Main()
    {
        int meow = 1 << 63;  // Generates S2183.
    }

    enum MyEnum
    {
        Meow = 1 << 63  // Does not generate S2183.
    }
}

To me it seems OK that it doesn’t trigger when shifting by 0 in enums, but not by the number of bits or more, as that’s most probably a bug.

Hello @Trisibo,

Thank you for raising this with us!

It is indeed a false negative, I have opened a ticket in our backlog so we can tackle it in the future.

Have a nice day,

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.