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

2010-03-05 Thread erh+gcc at nimenees dot com
(Same behaviour exists on gcc version 4.1.2 20080704 (Red Hat 4.1.2-46))

When compiling a c++ program it would be very useful to get warnings about
missing prototypes.  This works in C mode, but not in c++ mode.  Example:
cat > foo.cpp 

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

2010-03-06 Thread erh+gcc at nimenees dot com


--- Comment #2 from erh+gcc at nimenees dot com  2010-03-06 21:34 ---
So does this mean bug #13687 is going to be reopened?  Or is there some
workaround that hasn't been mentioned?


-- 


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



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

2010-03-07 Thread erh+gcc at nimenees dot com


--- Comment #4 from erh+gcc at nimenees dot com  2010-03-08 04:02 ---
(In reply to comment #3)
> (In reply to comment #2)
> > So does this mean bug #13687 is going to be reopened?  Or is there some
> > workaround that hasn't been mentioned?
> 
> No. I think the issue has been discussed at length there.
> W.
> 

I see a few comments that don't at all explain why you would not want to have
this warning available in c++.  The argument there seems to be that is is
unnecesary b/c you can't "call a function without a prior prototype", but to my
mind that fact is an argument FOR having the warning.

You need a prototype when use call a function and, more importantly, due to the
fact that c++ mangles function names based on the exact types of the parameters
that prototype NEEDS to be completely in sync with the function definition,
otherwise it's effectively prototyping a non-existent function.

Yes, you'll get an error at link time if the function actually gets called 
somewhere, but I don't understand why you *wouldn't* want to point out the
discrepancy between the header file and the cpp file early.  i.e. at a point
during a build where a developer will be able to fix it more easily because the
warning is telling him at least one of the files that he has to look at.

Are you really saying that this isn't a useful piece of information to provide
to the developer?
Is there some problem that I'm not seeing that turning on this warning will
cause?
Is enabling it for c++ code difficult due to how gcc is implemented?
I'm confused as to why there is such opposition to this and I feel like there's
some key point here that I'm missing.

(btw, I tried the trivial change in c.opt (gcc 4.1.3) of just allowing the
command line option, but no warning appeared when I compiled with
-Wmissing-prototypes.  I guess there's something else that needs to be done,
but I have no idea what)


-- 

erh+gcc at nimenees dot com changed:

   What|Removed |Added

 Status|RESOLVED|UNCONFIRMED
 Resolution|DUPLICATE   |


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



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

2010-03-08 Thread erh+gcc at nimenees dot com


--- 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



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

2010-03-08 Thread erh+gcc at nimenees dot com


--- Comment #10 from erh+gcc at nimenees dot com  2010-03-08 16:35 ---
(In reply to comment #8)
> > The code that calls the function also *compiles* cleanly, and only the link
> > fails.
> 
> No, the code calling it does not compile cleanly if there's no previous
> declaration.
> It only compiles cleanly if there's an overload that is similar enough that it
> can be called via conversion.

If you're maintaining existing code there's a good chance that there will be a
similar enough overload.

> Do you really write overloads that are so similar, and then declare them in
> separate headers?

I never said anything about separate headers.  You don't need separate headers,
you just need to be a bit forgetful about what needs to be changed in a single
header.

> Don't do that.  Even ignoring potential ambiguities, it's asking for problems
> if the declarations aren't in a single header.
> 
> But I doubt you really have code like that, so I don't find your argument
> convincing.

Actually, yes I DID have code like that, although it wasn't intended to be that
way.  What happened was that I rewrote a function to use "const char *" instead
of "char *", and forgot to remove the old one.  However, that was a rare
occurrence; most of the cases it's just changing the function signature w/o
many changes to the implementation code.

The case that I keep running into all the time is that I convert a bunch of
code from "char *" from "const char*", then go update the header to match up
with the code, but happen to miss one (or more) prototypes that needed to be
changed.  The code compiles, 
Then sometime later, I (or another developer) build some code that uses the
library, a link error occurs, and we're sitting there scratching our heads
wondering why it's complaining about a function that, at first glance, appears
to exist.


-- 


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



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

2010-03-08 Thread erh+gcc at nimenees dot com


--- Comment #11 from erh+gcc at nimenees dot com  2010-03-08 16:36 ---
(In reply to comment #6)
> You don't need a new warning to get what you want, as long as you put your
> functions in a namespace:
> 
...snip...
> error: 'void ns::myfunc(const char*)' should have been declared inside 'ns'

hmm... is there a way to have g++ put everything into some default namespace so
I always get errors like this?  If so, that would satisfy my needs.
I'd prefer not to have to change all my code to add the namespace stuff.


-- 


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



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

2010-03-15 Thread erh+gcc at nimenees dot com


--- Comment #13 from erh+gcc at nimenees dot com  2010-03-15 17:30 ---
(In reply to comment #12)
> (In reply to comment #11)
> > hmm... is there a way to have g++ put everything into some default 
> > namespace so
> > I always get errors like this?  If so, that would satisfy my needs.
> 
> No.

Do you know of some kind of tool other than gcc that would warn about missing
prototypes?  Not having this warning available is really causing me a lot of
pain with the project I'm working on.


-- 


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