[Bug c++/105497] New: -Wswitch ignores [[maybe_unused]] for an enumerator

olafurw at gmail dot com gcc-bugzilla@gcc.gnu.org
Thu May 5 15:37:11 GMT 2022


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105497

            Bug ID: 105497
           Summary: -Wswitch ignores [[maybe_unused]] for an enumerator
           Product: gcc
           Version: 11.3.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: olafurw at gmail dot com
  Target Milestone: ---

enum class Button
{
    Left,
    Right,
    Middle,
    NumberOfButtons [[maybe_unused]]
};

int main()
{
    Button b = Button::Left;
    switch (b) {
        case Button::Left:
        case Button::Right:
        case Button::Middle:
            break;
//#ifdef __GNUC__
//        case Button::NumberOfButtons:
//            __builtin_unreachable();
//#endif
    }
}

https://godbolt.org/z/d5M5MYc45

No warning generated for Clang or MSVC but it does for GCC. Works with
__builtin_unreachable()

LLVM bug report about the same thing:
https://bugs.llvm.org/show_bug.cgi?id=36231


More information about the Gcc-bugs mailing list