This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
c++/2045: no warning when a non void function falls through without a return value; bad code generated.
- To: gcc-gnats at gcc dot gnu dot org
- Subject: c++/2045: no warning when a non void function falls through without a return value; bad code generated.
- From: jamie at turbolabs dot com
- Date: 21 Feb 2001 02:14:08 -0000
- Reply-To: jamie at turbolabs dot com
>Number: 2045
>Category: c++
>Synopsis: no warning when a non void function falls through without a return value; bad code generated.
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: unassigned
>State: open
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Tue Feb 20 18:16:01 PST 2001
>Closed-Date:
>Last-Modified:
>Originator: Jamie Painter
>Release: gcc version 2.95.2 19991024 (release)
>Organization:
>Environment:
i586-pc-linux
TurboLinux workstaion distribution 6.0
glibc-2.1.2-15, libstdc++-2.10-2
>Description:
A non void function that fails to return a value does not always yield a warning or error message, even with -Wall, using gcc 2.95.2. The attached example demonstrates this.
It's quite small before running through the preprocessor :-)
Worse, the generated code ends up calling the return value destructor, even though a return value was never constructed.
I also tried this with the current gcc-3_0-branch snapshot via http://www.codesourcery.com/gcc-compile.shtml. This compiler version gives a warning (as it should), but still generates bad code (deconstructing an object that was never constructed). Without -Wall, no warning is given, but bad code is generated.
>How-To-Repeat:
g++ -Wall -o t1 t1.cpp
>Fix:
Return a value from the non void function.
>Release-Note:
>Audit-Trail:
>Unformatted:
----gnatsweb-attachment----
Content-Type: application/octet-stream; name="t1.ii"
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="t1.ii"