Bug 59546

Summary: Incorrect warnings about code that "will never be executed"
Product: [Retired] Red Hat Raw Hide Reporter: Bill Crawford <billc>
Component: gccAssignee: Jakub Jelinek <jakub>
Status: CLOSED CURRENTRELEASE QA Contact:
Severity: low Docs Contact:
Priority: medium    
Version: 1.0   
Target Milestone: ---   
Target Release: ---   
Hardware: i386   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2004-10-02 19:25:21 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Attachments:
Description Flags
Offending example of source, distilled from a real-life example
none
Oddly, NO warning is issued for this case (where the last line IS unreachable due to the two return statements) none

Description Bill Crawford 2002-02-10 03:43:08 UTC
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-10 03:44:01 UTC
Created attachment 45157 [details]
Offending example of source, distilled from a real-life example

Comment 2 Bill Crawford 2002-02-10 03:55:13 UTC
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 12:08:39 UTC
Fixed in CVS, will appear in gcc-3.1-0.22.

Comment 4 Bill Crawford 2002-03-09 01:12:38 UTC
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 19:25:21 UTC
Definitely not present in gcc 3.2.