[prev in list] [next in list] [prev in thread] [next in thread] 

List:       gcc-bugs
Subject:    -Wreturn-type failing to report a warning (gcc-2.95.2)
From:       Andrew Pollard <andrew () andypo ! net>
Date:       2001-02-27 13:20:21
[Download RAW message or body]


Hi,

System:   RedHat7.0/x86
Compiler: Self compiled gcc-2.95.2

There seems to be a bug in gcc-2.95.2 wrt -Wreturn-type in that if
a user defined class has a destructor, and it is passed as an
argument to a function that has a return type, but no return is present,
then no warning is given.

main.cc
----------------------------------------------------------------------
struct A {};
struct B { ~B(); };

int foo(A) {}
int bar(B) {}
----------------------------------------------------------------------

% /usr/local/gcc-2.95.2-i686-pc-linux-gnu/bin/g++ -v
Reading specs from /usr/local/gcc-2.95.2-i686-pc-linux-gnu/lib/gcc-lib/i686-pc-linux-gnu/2.95.2/specs
gcc version 2.95.2 19991024 (release)

% /usr/local/gcc-2.95.2-i686-pc-linux-gnu/bin/g++ -Wreturn-type -c main.cc
main.cc: In function `int foo(A)':
main.cc:4: warning: control reaches end of non-void function `foo(A)'

But there is no such warning for 'bar(B)'.

[ This has caught us out a couple of times :-) ]

(Same thing happens with egcs-1.1.2 and gcc-2.96.20000731(RH7)[which
incidentally doesn't need the -Wreturn-type to trigger the warning])

Haven't managed to try the CVS gcc or the gcc-3.0 branch.

Andrew.
--
 Andrew Pollard, ASI/Brooks Automation  | home: andrew@andypo.net
670 Eskdale Road, Winnersh Triangle, UK | work: Andrew_Pollard@autosim.com
  Tel/Fax:+44 (0)118 9215603 / 921566   | http://www.andypo.net

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic