http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56566
Bug #: 56566 Summary: bogus "is narrower than values of its type" warning Classification: Unclassified Product: gcc Version: unknown Status: UNCONFIRMED Severity: normal Priority: P3 Component: c AssignedTo: unassig...@gcc.gnu.org ReportedBy: ppluzhni...@google.com Test: struct S { enum E { N = -1, Z = 0 } e : 1; }; int main() { return 0; } Using current trunk (r196526): gcc -c tt.c tt.c:5:3: warning: ‘e’ is narrower than values of its type [enabled by default] } e : 1; ^ g++ -c tt.c tt.c:5:9: warning: ‘S::e’ is too small to hold all values of ‘enum S::E’ [enabled by default] } e : 1; ^ 7.2/7 of the C++ standard says for an enumeration where emin is the smallest enumerator and emax is the largest, the values of the enumeration are the values in the range bmin to bmax, defined as follows: Let K be 1 for a two’s complement representation and 0 for a one’s complement or sign-magnitude representation. bmax is the smallest value greater than or equal to max(|emin| − K, |emax|) and equal to 2^M − 1, where M is a non-negative integer. bmin is zero if emin is non- negative and −(bmax + K) otherwise. The size of the smallest bit-field large enough to hold all the values of the enumeration type is max(M, 1) if bmin is zero and M + 1 otherwise. given emin = -1, emax = 0, K = 1 then max(|emin|-K,|emax|) = max(0,0) = 0 therefore bmax = 0, M = 0, bmin = -(bmax+K) = -1, size = M+1 = 1