This is the mail archive of the gcc@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]

Re: Erroneous program misbehaves without warning


> 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


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