Bug 59546 - Incorrect warnings about code that "will never be executed"
Summary: Incorrect warnings about code that "will never be executed"
Keywords:
Status: CLOSED CURRENTRELEASE
Alias: None
Product: Red Hat Raw Hide
Classification: Retired
Component: gcc
Version: 1.0
Hardware: i386
OS: Linux
medium
low
Target Milestone: ---
Assignee: Jakub Jelinek
QA Contact:
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2002-02-10 03:43 UTC by Bill Crawford
Modified: 2007-04-18 16:40 UTC (History)
0 users

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2004-10-02 19:25:21 UTC
Embargoed:


Attachments (Terms of Use)
Offending example of source, distilled from a real-life example (984 bytes, text/plain)
2002-02-10 03:44 UTC, 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-10 03:55 UTC, Bill Crawford
no flags Details

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.


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