public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "tortoise_74 at yahoo dot co.uk" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug c/51294] New: spurious warning from -Wconversion in C and C++ Date: Thu, 24 Nov 2011 11:43:00 -0000 [thread overview] Message-ID: <bug-51294-4@http.gcc.gnu.org/bugzilla/> (raw) http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51294 Bug #: 51294 Summary: spurious warning from -Wconversion in C and C++ Classification: Unclassified Product: gcc Version: 4.7.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c AssignedTo: unassigned@gcc.gnu.org ReportedBy: tortoise_74@yahoo.co.uk The code below produces a spurious warning when compiled with -Wconversion. 0 is a const so the compiler should be able to choose the correct type. This works with gcc 4.1 on redhat 5 but not the latest snapshot of gcc 4.7 (which I am trialing for its c++11 support). I do not have any intermediate compiler versions to test with. spurious.cpp: class foo { char bar; foo(bool haveBar, char bar_): bar(haveBar?bar_:0) { } }; ## test.sh #!/bin/sh gcc --version gcc -Wconversion -c spurious.cpp export LD_LIBRARY_PATH=/opt/gcc4.7/lib:$LD_LIBRARY_PATH export PATH=/opt/gcc4.7/bin:$PATH /opt/gcc4.7/bin/gcc --version /opt/gcc4.7/bin/gcc -Werror -Wconversion -c spurious.cpp ## brucea@:home/brucea/spurious>./test.sh gcc (GCC) 4.1.2 20080704 (Red Hat 4.1.2-51) Copyright (C) 2006 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. gcc (GCC) 4.7.0 20111119 (experimental) Copyright (C) 2011 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. spurious.cpp: In constructor ‘foo::foo(bool, char)’: spurious.cpp:8:25: error: conversion to ‘char’ from ‘int’ may alter its value [-Werror=conversion] cc1plus: all warnings being treated as errors ## The workaround is either to disable the warning with -Wno-conversion or add unecessary constants as below. I don't think this is acceptable. class foo2 { static const char zero = 0; char bar; foo2(bool haveBar, char bar_): bar(haveBar?bar_:zero) { } }; This is also a bug in the C front-end: void foo(int haveBar, char bar_) { char zuul = haveBar?bar_:0; }
next reply other threads:[~2011-11-24 11:34 UTC|newest] Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top 2011-11-24 11:43 tortoise_74 at yahoo dot co.uk [this message] 2011-11-24 11:51 ` [Bug c/51294] " tortoise_74 at yahoo dot co.uk 2011-11-24 12:45 ` redi at gcc dot gnu.org 2011-11-24 16:09 ` [Bug c/51294] spurious warning from -Wconversion in C and C++ in conditional expressions manu at gcc dot gnu.org 2011-11-24 17:58 ` tortoise_74 at yahoo dot co.uk 2011-11-24 19:09 ` redi at gcc dot gnu.org 2012-01-05 15:33 ` manu at gcc dot gnu.org 2012-03-24 10:18 ` manu at gcc dot gnu.org 2012-03-26 10:17 ` paolo.carlini at oracle dot com 2012-03-30 11:08 ` paolo.carlini at oracle dot com 2012-05-12 18:21 ` paolo.carlini at oracle dot com 2012-05-12 19:10 ` manu at gcc dot gnu.org 2012-11-07 16:59 ` manu at gcc dot gnu.org 2012-11-07 17:07 ` manu at gcc dot gnu.org
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=bug-51294-4@http.gcc.gnu.org/bugzilla/ \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).