Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 192387 - gcc-4.2.0 Compiles C++ program containing value-returning functions that don't return a value
Summary: gcc-4.2.0 Compiles C++ program containing value-returning functions that don'...
Status: RESOLVED INVALID
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: [OLD] Core system (show other bugs)
Hardware: All Linux
: Normal enhancement (vote)
Assignee: Gentoo Toolchain Maintainers
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-09-13 06:40 UTC by Robert Miesen
Modified: 2007-09-13 07:34 UTC (History)
0 users

See Also:
Package list:
Runtime testing required: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Robert Miesen 2007-09-13 06:40:54 UTC
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.".


Example program:

====================START OF PROGRAM====================
/**
** \author  Robert Miesen
** \date    09/04/2007 -- Time-stamp: \<09/04/2007\>
** \version 1.0
** \file    main.cpp
** \brief   Contains code to demonstrate a bug in GCC: that it doesn't flag cases where a function that should return a value doesn't.
**
** \remarks Input: 
**    - N/A.
** \remarks Output: 
**    - TBD.
** \remarks Exit Codes:
**    - 0: Normal Execution
**/ 

#include <iostream>

  //
  //  Function Prototypes:
  //
bool
Func1(int param1);


int
main( int argc, char *argv[] ) 
{
  std::cout << "The value of 5*5 is: " <<  Func1(5) << "\n";
  
  
  return 0;
}



bool
Func1(int param1)
{
  int var1 = param1*param1;
	// Hay, I didn't specify a return value...this shouldn't 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!



System information:


gcc:

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)
Comment 1 SpanKY gentoo-dev 2007-09-13 07:34:07 UTC
it's a feature, not a bug

and of course you'll get random return values ... you'll get whatever happens to be in the %eax

if you want a different answer, open a bug at http://gcc.gnu.org/