[cfe-dev] Possibly invalid enum tautology warning

David Blaikie dblaikie at gmail.com
Mon Aug 8 10:21:43 PDT 2011


> C99 6.7.2.2p3 specifies "If the first enumerator has no =, the value of its enumeration constant is 0." C++ does the same.
> ...
> C99 and C++98/03 say nothing about this. C++0x tried to clean it up a little based on what the committee felt was the intent in C and C++. See C++0x N3290 7.2 [dcl.enum]p7 for the full details, but the relevant conclusion is that, if the smallest enumerator is non-negative, then the values allowed in the enumeration are all non-negative.

Thanks for the references, Doug. Yes, that would've surprised me if
storing any non-enum value in an enum was UB - as much as I'd like
that to be the case, it hasn't felt like the language really tried to
make them that safe. (enum classes in C++0x I guess are meant to be
safer, but I haven't read the finer points of those either) But this
guarantee sounds good enough for this case, as you mentioned.

- David




More information about the cfe-dev mailing list