Bug 48094 - Lack of return statement not always reported.
Summary: Lack of return statement not always reported.
Keywords:
Status: CLOSED DEFERRED
Alias: None
Product: Red Hat Linux
Classification: Retired
Component: gcc
Version: 7.1
Hardware: i586
OS: Linux
medium
low
Target Milestone: ---
Assignee: Jakub Jelinek
QA Contact: David Lawrence
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2001-07-09 17:32 UTC by Kenton Varda
Modified: 2007-04-18 16:34 UTC (History)
0 users

Fixed In Version:
Clone Of:
Environment:
Last Closed: 2001-07-09 17:32:40 UTC
Embargoed:


Attachments (Terms of Use)

Description Kenton Varda 2001-07-09 17:32:37 UTC
From Bugzilla Helper:
User-Agent: Mozilla/5.0 (X11; U; Linux 2.4.2-2 i686; en-US; 0.7) Gecko/20010316

Description of problem:
I had a hard time creating a contrived example of this bug, so here is the
actual function in which I originally found the bug...

#include <string>
#include <iostream>

string ObjectName2Filename(string moduleName)
{
    int pos;
    while((pos = moduleName.find_first_of(':')) >= 0)
        moduleName.replace(pos, 2, "/");
//  return moduleName;   //removing this line should cause an error
}

int main()
{
    cout << ObjectName2Filename("package::Object") << endl;
    return 0;
}



How reproducible:
Some code does it, some doesn't, but the same piece of code will always
give the same result.

Steps to Reproduce:
1. Compile the code with GCC.  Use -O2 and -Wall if you like, but they
won't make a difference.
2. Run it.

Actual Results:
Code compiled, ran, and segfaulted.  I assume the segfault occurred due to
the function returning some sort of undefined garbage rather than a string.
 Strangely, if -O2 was not used, the program would not segfault, but would
print a blank line -- still not what it was supposed to do, though.

Expected Results:
An error or warning indicating the problem.

Additional info:

If you un-comment the return statement, everything works great.

I have a funny way of forgetting return statements sometimes, and random
segfaults (which usually occur later on in the code) don't help me find my
mistake.  :)  Then again, the bug has made me get used to doing personal
code reviews, so some good has come of it.  :)

I am using gcc 2.96-85.

Comment 1 Jakub Jelinek 2001-07-25 14:32:39 UTC
This has been fixed in G++ 3.0 with
http://gcc.gnu.org/ml/gcc-patches/2000-10/msg00115.html
and a bunch of follow-up patches. But I don't feel safely about adding them
in now, because it could destabilize the compiler.


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