This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Missing "control reaches end of non-void function" warning in egcs.


Hi,

I found a problem in the g++ compiler.

I'm using compiler which is included by default in the SuSE 6.1 Linux 
distribution
gcc version egcs-2.91.66 19990314 (egcs-1.1.2 release)

I have already posted this problem in nl.comp.programmeren and other 
people have reproduced the same problem with "gcc version 2.95 19990728".

The problem is that the compiler doesn't always warn about not always 
returning a value. I managed to reduce the problem to the following code 
fragment:

------ test.cc ------
#include <string>

int global_thing = 1;

class something { public: something(something &org){}; };

bool DoWithoutParameter()
{ if (global_thing == 5)  return false; }

bool DoWithInteger(int some_parameter)
{ if (global_thing == 5)  return false; }

bool DoWithString(string some_parameter)
{ if (global_thing == 5)  return false; }

bool DoWithSomething(something some_parameter)
{ if (global_thing == 5)  return false; }

bool DoWithRefString(string &some_parameter)
{ if (global_thing == 5)  return false; }

-----------------------

When I run "g++ -Wall -c test.cc" I get:

testje.cc: In function `bool DoWithoutParameter()':
testje.cc:8: warning: control reaches end of non-void function
`DoWithoutParameter()'
testje.cc: In function `bool DoWithInteger(int)':
testje.cc:11: warning: control reaches end of non-void function
`DoWithInteger(int)'
testje.cc: In function `bool DoWithSomething(class something)':
testje.cc:17: warning: control reaches end of non-void function
`DoWithSomething(something)'
testje.cc: In function `bool DoWithRefString(class string &)':
testje.cc:20: warning: control reaches end of non-void function
`DoWithRefString(string &)'

As you can see the only situation where the compiler doesn't warn is when 
the function parameter is of the type string. I found out about this 
problem when I tried to port my code using de M$-VC 6.0 compiler (which 
did complain about this bug in my code).

--

Best regards,

Niels.

=======================================================================
| ir. Niels Basjes              | National Aerospace Laboratory |  _  |
| Phone       : +31-20-5113381  | Anthony Fokkerweg 2           | /   |
| Fax         : +31-20-5113210  | 1059 CM Amsterdam             |(NLR)|
| E-Mail@NLR  : Basjes@NLR.nl   | The Netherlands               |  _/ |
| E-Mail@Home : Niels@Basjes.nl | http://www.nlr.nl             |     |
=======================================================================
PGP-Key FC5709F5 : http://www.wirehub.nl/~basjesn/PGPKeys.asc



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]