Bug 48094

Summary: Lack of return statement not always reported.
Product: [Retired] Red Hat Linux Reporter: Kenton Varda <temporal>
Component: gccAssignee: Jakub Jelinek <jakub>
Status: CLOSED DEFERRED QA Contact: David Lawrence <dkl>
Severity: low Docs Contact:
Priority: medium    
Version: 7.1   
Target Milestone: ---   
Target Release: ---   
Hardware: i586   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2001-07-09 17:32:40 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:

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.