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]
Other format: [Raw text]

[Bug c++/43272] -Wmissing-prototypes doesn't work in C++ mode



------- Comment #7 from erh+gcc at nimenees dot com  2010-03-08 16:07 -------
(In reply to comment #5)
> What I'm saying is that this entire discussion is already present in PR13687
> and that there is nothing more to say. The warning exists in C because it
> can lead to hard-to-find bugs in C code because you can call a function
> without a prototype in C. You can't do that in C++, and on top of that you
> can overload functions in C++ which makes it impossible to determine for a
> compiler whether a prototype matches a definition.
> 
> Warnings are not generally meant to make programming simpler (as in the case
> you are making) but to warn about cases that can lead the compiler to generate
> code that may not have been intended that way but that compiles cleanly
> anyway. 

That's exactly my point!  This is a case where the (function implementation)
code DOES compile cleanly, but there is an obvious problem that causes it to be
unusable.
The code that calls the function also *compiles* cleanly, and only the link
fails.

Furthermore, the fact that you can overload functions means that this causes
even MORE of a problem.  Let's say you have two functions defined:
int foo(int blue)
{
    return 0;
}
int foo(long blue)
{
    return 1;
}

And you decide to call one of them from somewhere else:

...
long somearg = 123;
int retval = foo(somearg);
...

but you forgot to add the prototype for "int foo(long);".  In this case, all
the code compiles AND links, but the wrong function is called.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43272


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