This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/24770] New: Incorrect "unreachable code" warning from 3.4.3 under specific conditions


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]