Looking at the specification [[maybe_unused]] , she states:
Appears in the class declaration, typedef, variable, non-static data member, function, enumeration or enumerator. If the compiler issues warnings about unused objects, this warning is suppressed for any declared Maybe_unused entity.
As the enumerator says, I expect him to have a precedent. As the only thing I could come up with is a warning -Wswitch , I tried it with Clang, GCC and MSVC.
enum A { B, C [[maybe_unused]] }; void f(A a) { switch (a) { case B: break; } }
All 3 compilers give me the following warnings:
<source>:9:13: warning: enumeration value 'C' not handled in switch [-Wswitch] switch (a) ^
Living code
Is this a valid use case for using this attribute, are there any other use cases for adding the attribute in this place, or is it just a useless addition?
c ++ language-lawyer attributes c ++ 17
Jvpen
source share