Bug 59546 - Incorrect warnings about code that "will never be executed"
Incorrect warnings about code that "will never be executed"
Status: CLOSED CURRENTRELEASE
Product: Red Hat Raw Hide
Classification: Retired
Component: gcc (Show other bugs)
1.0
i386 Linux
medium Severity low
: ---
: ---
Assigned To: Jakub Jelinek
:
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2002-02-09 22:43 EST by Bill Crawford
Modified: 2007-04-18 12:40 EDT (History)
0 users

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2004-10-02 15:25:21 EDT
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)
Offending example of source, distilled from a real-life example (984 bytes, text/plain)
2002-02-09 22:44 EST, Bill Crawford
no flags Details
Oddly, NO warning is issued for this case (where the last line IS unreachable due to the two return statements) (851 bytes, text/plain)
2002-02-09 22:55 EST, Bill Crawford
no flags Details

  None (edit)
Description Bill Crawford 2002-02-09 22:43:08 EST
Description of Problem:
g++ seems to erroneously report a statement as "unreachable" ...

Version-Release number of selected component (if applicable):
[bill@pikachu bill]$ rpm -q gcc-c++
gcc-c++-3.1-0.21

How Reproducible:
Well, I'll attach the code in a moment ...

[bill@pikachu tmp]$ c++ -O2 -W -Wall -Weffc++ -Wunreachable-code -g -c -o bug4.o
bug4.c++
bug4.c++: In function `void three(fum*, const char*)':
bug4.c++:63: warning: will never be executed
bug4.c++:58: warning: will never be executed

The code at line 58 is a return statement which certainly should be executed. 
The odd part is line 63: it should be reachable if the condition at line 45 is
not met during the loop.  Unless I'm losing my marbles again.  But since gcc
doesn't know what value is going to be passed in, it can't know whether the
condition will be true.
Comment 1 Bill Crawford 2002-02-09 22:44:01 EST
Created attachment 45157 [details]
Offending example of source, distilled from a real-life example
Comment 2 Bill Crawford 2002-02-09 22:55:13 EST
Created attachment 45158 [details]
Oddly, NO warning is issued for this case (where the last line IS unreachable due to the two return statements)
Comment 3 Jakub Jelinek 2002-02-13 07:08:39 EST
Fixed in CVS, will appear in gcc-3.1-0.22.
Comment 4 Bill Crawford 2002-03-08 20:12:38 EST
I'm still seeing a warning for the first example, which I'm pretty sure is
wrong.

[bill@pikachu tmp]$ c++ -W -Wall -Wunreachable-code -O2 -c bug4.c++
bug4.c++: In function `void three(fum*, const char*)':
bug4.c++:57: warning: will never be executed
bug4.c++:47: warning: will never be executed

I am however now getting a valid warning for the second example, as I should:

[bill@pikachu tmp]$ c++ -W -Wall -Wunreachable-code -O2 -c bug5.c++
bug5.c++: In function `void three(fum*, const char*)':
bug5.c++:56: warning: will never be executed

If it'll help I can probably supply some more examples ... I get loads of
warnings from some code I'm messing with at the moment.  It's horrid code, but
works ...
Comment 5 Richard Henderson 2004-10-02 15:25:21 EDT
Definitely not present in gcc 3.2.

Note You need to log in before you can comment on or make changes to this bug.