[Bug c++/57164] New: enumerator value -1 is too large for underlying type ‘unsigned int’
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57164 Bug #: 57164 Summary: enumerator value -1 is too large for underlying type ‘unsigned int’ Classification: Unclassified Product: gcc Version: 4.8.0 Status: UNCONFIRMED Severity: minor Priority: P3 Component: c++ AssignedTo: unassig...@gcc.gnu.org ReportedBy: vvnic.ho...@gmail.com Having an enumerator with a negative value in an enumeration with an unsigned underlying type produces a compilation error. enum A : unsigned { B = -1 }; nicholas@ubuntu:~$ g++ test.cpp -std=c++11 test.cpp:2:7: error: enumerator value -1 is too large for underlying type ‘unsigned int’ B = -1 ^ Same error if any other unsigned type is used, or if a scoped enumeration is used. As per §7.2.5: "If the underlying type is fixed, the type of each enumerator prior to the closing brace is the underlying type and the constant-expression in the enumerator-definition shall be a _converted constant expression_ of the underlying type (5.19)" (emphasis added) As per §5.19.3: "A converted constant expression of type T is an expression, implicitly converted to a prvalue of type T, where the converted expression is a core constant expression and the implicit conversion sequence contains only user-defined conversions, lvalue-to-rvalue conversions (4.1), integral promotions (4.5), and _integral conversions_ (4.7) other than narrowing conversions (8.5.4)." (emphasis added) As per §4.7.2 "If the destination type is unsigned, the resulting value is the least unsigned integer congruent to the source integer" In other words, the above snippet should be equivalent to: enum A : unsigned { B = 4294967295 };
[Bug c++/57164] enumerator value -1 is too large for underlying type ‘unsigned int’
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57164 --- Comment #1 from Nicholas 2013-05-03 21:24:03 UTC --- (assuming 32-bit ints and two's complement)
[Bug c++/57170] New: No diagnostic for a negative case when switching over unsigned
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57170 Bug #: 57170 Summary: No diagnostic for a negative case when switching over unsigned Classification: Unclassified Product: gcc Version: 4.8.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ AssignedTo: unassig...@gcc.gnu.org ReportedBy: vvnic.ho...@gmail.com A signed->unsigned conversion is narrowing, so -1 is not a converted constant expression. However, the following emits no warning with -Wall, with or without -std=c++11: int main() { unsigned a = 10; switch (a) { case -1: break; } return 0; } But replacing "unsigned" with any smaller unsigned type (unsigned char or unsigned short) yields the following warning: test.cpp:4:9: warning: case label value is less than minimum value for type [enabled by default] case -1:
[Bug c++/58126] New: No diagnostic when inheriting an uninitialized const or reference member
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58126 Bug ID: 58126 Summary: No diagnostic when inheriting an uninitialized const or reference member Product: gcc Version: 4.8.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: vvnic.holas at gmail dot com The following code compiles without any warning or error: struct A { const int value1; int& value2; }; struct B : A {}; int main() { B b; // no error //A a; // error, as expected }