From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 3393 invoked by alias); 24 Nov 2011 15:47:00 -0000 Received: (qmail 3382 invoked by uid 22791); 24 Nov 2011 15:46:58 -0000 X-SWARE-Spam-Status: No, hits=-2.9 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00 X-Spam-Check-By: sourceware.org Received: from localhost (HELO gcc.gnu.org) (127.0.0.1) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 24 Nov 2011 15:46:44 +0000 From: "manu at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug c/51294] spurious warning from -Wconversion in C and C++ in conditional expressions Date: Thu, 24 Nov 2011 16:09:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c X-Bugzilla-Keywords: diagnostic X-Bugzilla-Severity: normal X-Bugzilla-Who: manu at gcc dot gnu.org X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Changed-Fields: Keywords CC Summary Message-ID: In-Reply-To: References: X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 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: 2011-11/txt/msg02419.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D51294 Manuel L=C3=B3pez-Ib=C3=A1=C3=B1ez changed: What |Removed |Added ---------------------------------------------------------------------------- Keywords| |diagnostic CC| |manu at gcc dot gnu.org Summary|spurious warning from |spurious warning from |-Wconversion in C and C++ |-Wconversion in C and C++ | |in conditional expressions --- Comment #3 from Manuel L=C3=B3pez-Ib=C3=A1=C3=B1ez 2011-11-24 15:46:16 UTC --- (In reply to comment #2) > (In reply to comment #0) > > 0 is a const so the compiler should be able to choose the correct type. >=20 > 0 is an int, so the compiler is required by the standard to make the > conditional expression (haveBar?bar_:0) have type int. >=20 > It shouldn't warn though, as the conversion from int to char won't alter = the > value. This was implemented in this patch: http://gcc.gnu.org/ml/gcc-patches/2009-08/msg00582.html which was rejected. Perhaps a cut-down version that addresses only this iss= ue would be accepted. But perhaps no. Feel free to take it. BTW, clang does not warn for this case, while it does if bar_ is an int: pr51294.c:3:23: warning: implicit conversion loses integer precision: 'int'= to 'char' [-Wconversion] char zuul =3D haveBar?bar_:0; ~^~~~ 1 warning generated. It also points to the correct location of the issue, whereas GCC doesn't.