From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 10401 invoked by alias); 11 Jun 2010 14:56:22 -0000 Received: (qmail 10285 invoked by uid 48); 11 Jun 2010 14:56:03 -0000 Date: Fri, 11 Jun 2010 14:56:00 -0000 Message-ID: <20100611145603.10284.qmail@sourceware.org> X-Bugzilla-Reason: CC References: Subject: [Bug c++/44500] [C++0x] Bogus narrowing conversion error In-Reply-To: Reply-To: gcc-bugzilla@gcc.gnu.org To: gcc-bugs@gcc.gnu.org From: "redi at gcc dot gnu dot org" Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org X-SW-Source: 2010-06/txt/msg01319.txt.bz2 ------- 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(); // 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