From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 13874 invoked by alias); 9 Nov 2005 23:51:21 -0000 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org Received: (qmail 13863 invoked by uid 48); 9 Nov 2005 23:51:18 -0000 Date: Wed, 09 Nov 2005 23:51:00 -0000 Subject: [Bug c++/24770] New: Incorrect "unreachable code" warning from 3.4.3 under specific conditions X-Bugzilla-Reason: CC Message-ID: Reply-To: gcc-bugzilla@gcc.gnu.org To: gcc-bugs@gcc.gnu.org From: "dgsteffen at numerica dot us" X-SW-Source: 2005-11/txt/msg01364.txt.bz2 List-Id: This may be a duplicate of 8828, I'm not sure. (8828 is marked 'resolved' for 3.2.) The following short program produces an incorrect warning about unreachable code; this error is fragile, in that changing just about anything results in correct behavior (e.g. no warning); details follow. The code is this: #include #include using namespace std; inline double DoThing(int dim = 3) { switch (dim) { case 2: return 2; case 3: return 3; default: return 4; } } int main() { cout << sqrt( DoThing(2) ) << endl; } The compile command is this: /usr/local/compilers/3.4/bin/c++ -Wall -Werror -O2 -o check check.C and the result is: check.C: In function `int main()': check.C:9: warning: unreachable code at beginning of switch statement Changing the value passed into DoThing (or removing it) does not change the behavior. Things that _do_ change the behavior (e.g. result in no warnings and a correct compile) are: compiling without optimization; remove 'inline'; change return type of DoThing to int; don't take the sqrt of the answer. Unfortunately I don't have a more recent version to test with. GCC 3.3 and 3.2 do not display this behavior. Details about our compiler: /usr/local/compilers/3.4/bin/c++ -v Reading specs from /usr/local/compilers/.gcc-3.4.3/bin/../lib/gcc/i686-pc-linux-gnu/3.4.3/specs Configured with: ./configure --prefix=/scratch/mpdegroat/software/gcc-3.4.3/.gcc-3.4.3 --enable-shared --enable-threads=posix --enable-__cxa_atexit --disable-checking --with-system-zlib Thread model: posix gcc version 3.4.3 Please don't hesitate to bug me for more information! Thanks very much. Dave Steffen, Ph.D. Software Engineer IV Numerica Corporation ph (970) 419-8343 x27 fax (970) 223-6797 dgsteffen@numerica.us -- Summary: Incorrect "unreachable code" warning from 3.4.3 under specific conditions Product: gcc Version: 3.4.3 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: dgsteffen at numerica dot us GCC build triplet: i686-pc-linux-gnu GCC host triplet: i686-pc-linux-gnu GCC target triplet: i686-pc-linux-gnu http://gcc.gnu.org/bugzilla/show_bug.cgi?id=24770