------- Comment #11 from redi at gcc dot gnu dot org 2010-06-11 14:56 ------- (In reply to comment #9) > I understand now after the implicit promotion to int of a non constant value > the result of the narrowing operation can't be guaranteed to fit in the > original type. But I still think it shouldn't give an error, and if the > standard says so, I think it is flawed in this regard ;-) > > Consider > > g<INT_MAX, INT_MAX>(); // Warning, but no Error
The integer overflow means this is undefined behaviour. But it is not a narrowing conversion according to the rules of 8.5.4/6 > despite it can be proven that the value will not fit and this is very likely > an > error. Opposing to > > char c,d; > A a = { c+d }; > > which is very likely not an error and would only require a mild warning. IMHO. use A a = { char(c+d) } if you want the result to be a char not an int, then there is no narrowing conversion, because a narrowing conversion is an impliit conversion. (In reply to comment #10)iagnostic is IMHO clear. > prefer a bit longer message: > > error: C++0x does not allow narrowing conversion of "(((int)y) + 1)" from > "int" > to "char" inside { } I prefer the shorter message. If the compiler tells you there is an error it doesn't normally tell you the standard says so. If you compile with -std=c++0x then obviously that's the standard in question. -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=44500