Skip to content

Clang should warn when < or > is used instead of shift operators in enum initializers #168146

@ahatanak

Description

@ahatanak

clang should diagnose cases where comparison operators (< or >) are used instead of shift operators (<< or >>) in enumerator initializers. This is a common mistake that often occurs when defining bit flags or option enums.

For example:

enum E {
  kOptionOne    = 1ull << 0, // correct
  kOptionTwo    = 1ull < 1,  // oops!
  kOptionThree = 1ull < 2,  // oops!
};

Although these are valid C/C++ expressions, they are very likely to be errors in this context.

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang:diagnosticsNew/improved warning or error message in Clang, but not in clang-tidy or static analyzer

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions