[Bug c++/53745] [C++11] Poor diagnostic for ill-formed narrowing conversion in enumerator initializer

redi at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Thu Jun 21 17:52:00 GMT 2012


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53745

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |REOPENED
   Last reconfirmed|                            |2012-06-21
         Resolution|INVALID                     |
            Summary|Bitshifted value (1 << 31)  |[C++11] Poor diagnostic for
                   |within enumerator class is  |ill-formed narrowing
                   |calculated incorrectly      |conversion in enumerator
                   |during compilation.         |initializer
     Ever Confirmed|0                           |1

--- Comment #3 from Jonathan Wakely <redi at gcc dot gnu.org> 2012-06-21 17:51:43 UTC ---
Re-opening since the diagnostic could be better, the value is not "too large",
the problem is with the sign, not the magnitude.

enum E : unsigned long long { e = -1 };

e.cc:1:26: error: enumerator value -1 is too large for underlying type
'unsigned long long'

Clang gives a more accurate diagnostic, though not necessarily more helpful if
you don't know what a narrowing conversion is:

e.cc:1:25: error: enumerator value evaluates to -1, which cannot be narrowed to
type 'unsigned long long' [-Wc++11-narrowing]



More information about the Gcc-bugs mailing list