public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/24770]  New: Incorrect "unreachable code" warning from 3.4.3 under specific conditions
@ 2005-11-09 23:51 dgsteffen at numerica dot us
  2005-11-10  0:01 ` [Bug middle-end/24770] [3.4 Regression] " pinskia at gcc dot gnu dot org
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: dgsteffen at numerica dot us @ 2005-11-09 23:51 UTC (permalink / raw)
  To: gcc-bugs

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 <iostream>
#include <cmath>

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


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2006-03-01  4:59 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-11-09 23:51 [Bug c++/24770] New: Incorrect "unreachable code" warning from 3.4.3 under specific conditions dgsteffen at numerica dot us
2005-11-10  0:01 ` [Bug middle-end/24770] [3.4 Regression] " pinskia at gcc dot gnu dot org
2005-11-21  2:44 ` gdr at gcc dot gnu dot org
2006-03-01  4:59 ` gdr at gcc dot gnu dot org

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).