This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Erroneous program misbehaves without warning
- To: tom at womack dot net
- Subject: Re: Erroneous program misbehaves without warning
- From: "Martin v. Loewis" <martin at mira dot isdn dot cs dot tu-berlin dot de>
- Date: Sun, 21 Nov 1999 16:43:18 +0100
- CC: gcc at egcs dot cygnus dot com
- References: <000c01bf2f64$60015b80$5637f380@maths.nottingham.ac.uk>
> Consider the following program
>
> vector<pair<int,int> > pfact(int n)
> {
> cout << n;
> }
>
> void main(void)
> {
> pfact(6);
> pfact(7);
> }
>
> It compiles *without warnings* with gcc-2.95.2 (mingw32; Mumit Khan's port),
> but goes into an infinite loop after printing the six.
Thanks for your bug report. I cannot reproduce the problem, my copy of
2.95.2 reports
a.cc:1: `pair' was not declared in this scope
a.cc:1: parse error before `,'
a.cc: In function `int main(...)':
a.cc:8: implicit declaration of function `int pfact(...)'
which is due to missing includes. I assume you also had a line saying
#include <vector>
in your program. With that, I can reproduce the problem.
> OK, it's a stupid program - the function fails to return a value,
> and the value is then ignored by the caller - but it should at least
> print warnings, and ideally fail to compile; compiling to something
> which hangs is not the right idea at all.
With -Wall, the compiler reports
a.cc: In function `class vector<pair<int,int>,allocator<pair<int,int> > > pfact(int)':
a.cc:6: warning: control reaches end of non-void function `pfact(int)'
a.cc: At top level:
a.cc:9: return type for `main' changed to `int'
The compiler *must* accept this code after printing the warnings. It
is perfectly legal for a function not to return a value at the end,
for example if the end of the function is never reached.
Regards,
Martin