This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/33425] New: GCC Compiles C++ program containing value-returning functions that don't return a value
- From: "bobby_miesen at yahoo dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 13 Sep 2007 20:41:23 -0000
- Subject: [Bug c++/33425] New: GCC Compiles C++ program containing value-returning functions that don't return a value
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
GCC compiles and links a program with a function that should return a value,
yet doesn't. This violates the definition of a value-returning function. See
pp. 148 in "The C++ Programming Language: 3rd ed.".
GCC information:
Using built-in specs.
Target: i686-pc-linux-gnu
Configured with: /var/tmp/portage/sys-devel/gcc-4.2.0/work/gcc-4.2.0/configure
--prefix=/usr --bindir=/usr/i686-pc-linux-gnu/gcc-bin/4.2.0
--includedir=/usr/lib/gcc/i686-pc-linux-gnu/4.2.0/include
--datadir=/usr/share/gcc-data/i686-pc-linux-gnu/4.2.0
--mandir=/usr/share/gcc-data/i686-pc-linux-gnu/4.2.0/man
--infodir=/usr/share/gcc-data/i686-pc-linux-gnu/4.2.0/info
--with-gxx-include-dir=/usr/lib/gcc/i686-pc-linux-gnu/4.2.0/include/g++-v4
--host=i686-pc-linux-gnu --build=i686-pc-linux-gnu --disable-altivec
--enable-nls --without-included-gettext --with-system-zlib --disable-checking
--disable-werror --enable-secureplt --disable-libunwind-exceptions
--disable-multilib --enable-libmudflap --disable-libssp --disable-libgcj
--with-arch=i686 --enable-languages=c,c++,fortran --enable-shared
--enable-threads=posix --enable-__cxa_atexit --enable-clocale=gnu
Thread model: posix
gcc version 4.2.0 (Gentoo 4.2.0 p1.4)
GCC command invocation:
g++ -o functionReturnMayham -Wall main.cpp
Compiler Output:
main.cpp: In function 'bool Func1(int)':
main.cpp:41: warning: unused variable 'var1'
main.cpp:43: warning: control reaches end of non-void function
Example program:
====================START OF PROGRAM====================
/**
** \author Robert Miesen
** \date 09/04/2007 -- Time-stamp: \<09/13/2007\>
** \version 1.0
** \file main.cpp
** \brief Contains code to demonstrate a bug in GCC: that it doesn't flag as
an error cases where a function that should return a value doesn't.
**
** \remarks Input:
** - N/A.
** \remarks Output:
** - TBD.
** \remarks Exit Codes:
** - 0: Normal Execution
**
** Lessons Learned:
** - When compiling code, unless there is a complelling reason to do
otherwise, compile with the -Wall option. This will catch a bunch of shady (and
probably buggy) code automatically.
**/
//
// Function Prototypes:
//
bool
Func1(int param1);
int
main( int argc, char *argv[] )
{
return 0;
}
bool
Func1(int param1)
{
int var1 = param1*param1;
// Hay, I didn't specify a return value...this should not compile (but
it does!)
}
====================END OF PROGRAM====================
And wait, it gets worse! Just compile this sucker with -O2 optimizations and
you get RANDOM RETURN VALUES from the call of Func1 (this is because Func1
"returns" whatever is in eax at call-time)!
--
Summary: GCC Compiles C++ program containing value-returning
functions that don't return a value
Product: gcc
Version: 4.2.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: bobby_miesen at yahoo dot com
GCC build triplet: Linux 2.6.22-gentoo-r5 i686 Genuine Intel(R) CPU T2050 @
1.60GHz
GCC host triplet: Linux 2.6.22-gentoo-r5 i686 Genuine Intel(R) CPU T2050 @
1.60GHz
GCC target triplet: Linux 2.6.22-gentoo-r5 i686 Genuine Intel(R) CPU T2050 @
1.60GHz
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33425