public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/16402] New: g++ -Wmissing-declarations doesn't work
@ 2004-07-07  8:24 millerp at canb dot auug dot org dot au
  2004-07-07 11:06 ` [Bug c++/16402] " giovannibajo at libero dot it
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: millerp at canb dot auug dot org dot au @ 2004-07-07  8:24 UTC (permalink / raw)
  To: gcc-bugs

The gcc -Wmissing-declarations option is HUGELY useful.  It would be a Good
Thing if g++ -Wmissing-declarations worked in exactly the same way, for all the
same reasons.

-- 
           Summary: g++ -Wmissing-declarations doesn't work
           Product: gcc
           Version: 3.3
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: millerp at canb dot auug dot org dot au
                CC: gcc-bugs at gcc dot gnu dot org


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


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug c++/16402] g++ -Wmissing-declarations doesn't work
  2004-07-07  8:24 [Bug c++/16402] New: g++ -Wmissing-declarations doesn't work millerp at canb dot auug dot org dot au
@ 2004-07-07 11:06 ` giovannibajo at libero dot it
  2004-07-07 12:21 ` millerp at canb dot auug dot org dot au
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: giovannibajo at libero dot it @ 2004-07-07 11:06 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From giovannibajo at libero dot it  2004-07-07 11:06 -------
Can you please provide a minimum code snippet which should emit a warning with -
Wmissing-declarations but does not?

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |WAITING


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


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug c++/16402] g++ -Wmissing-declarations doesn't work
  2004-07-07  8:24 [Bug c++/16402] New: g++ -Wmissing-declarations doesn't work millerp at canb dot auug dot org dot au
  2004-07-07 11:06 ` [Bug c++/16402] " giovannibajo at libero dot it
@ 2004-07-07 12:21 ` millerp at canb dot auug dot org dot au
  2004-07-07 13:04 ` bangerth at dealii dot org
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: millerp at canb dot auug dot org dot au @ 2004-07-07 12:21 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From millerp at canb dot auug dot org dot au  2004-07-07 12:21 -------
/*
 * Example of missing warning: gcc -Wmissing-declarations will give a warning
with this code, g++ -Wmissing-declarations will not.
 *
 * The documentation for this option says "Warn if a global function is defined
without a previous declaration.  Do so even if the definition itself provides a
prototype.  Use this option to detect global functions that are not declared in
header files."
 *
 * For C++ the word "function" needs to cover operator declarator / definitions
as well.
 */
void function(){}

-- 


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


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug c++/16402] g++ -Wmissing-declarations doesn't work
  2004-07-07  8:24 [Bug c++/16402] New: g++ -Wmissing-declarations doesn't work millerp at canb dot auug dot org dot au
  2004-07-07 11:06 ` [Bug c++/16402] " giovannibajo at libero dot it
  2004-07-07 12:21 ` millerp at canb dot auug dot org dot au
@ 2004-07-07 13:04 ` bangerth at dealii dot org
  2004-07-07 14:39 ` pinskia at gcc dot gnu dot org
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: bangerth at dealii dot org @ 2004-07-07 13:04 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From bangerth at dealii dot org  2004-07-07 13:03 -------
The reasoning we don't have this option in c++ is the following: in C, it
is potentially harmful if you define a function, but do not provide a
prototype declaration in a header file, since you can call this function
without a prototype in another .c file with incompatible arguments. Example:
  a.c:
    int f(int i) {}

  b.c:
    void g() {
      f(1.1);
    }
This is legal, and passes a double value to f(), which will of course
yield 'interesting' results. The warning you cite reminds you that you better
have a declaration of a prototype in one of your header files, which then
should be included into b.c.

This reasoning doesn't work in C++: the call to f(1.1) is invalid code, unless
you provide a prototype. You get an error. There is no potential for mistakes
here, which is why the warning was never implemented.

I can see a few cases where the warning would make some sense, but you could
make a stronger case for your request if you could provide an explanation
why this option would be useful to have in C++ as well, rather than only in C.

W.

-- 


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


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug c++/16402] g++ -Wmissing-declarations doesn't work
  2004-07-07  8:24 [Bug c++/16402] New: g++ -Wmissing-declarations doesn't work millerp at canb dot auug dot org dot au
                   ` (2 preceding siblings ...)
  2004-07-07 13:04 ` bangerth at dealii dot org
@ 2004-07-07 14:39 ` pinskia at gcc dot gnu dot org
  2004-07-08  0:03 ` millerp at canb dot auug dot org dot au
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-07-07 14:39 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2004-07-07 14:39 -------
This is a dup of bug 8076.

*** This bug has been marked as a duplicate of 8076 ***

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|WAITING                     |RESOLVED
         Resolution|                            |DUPLICATE


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


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug c++/16402] g++ -Wmissing-declarations doesn't work
  2004-07-07  8:24 [Bug c++/16402] New: g++ -Wmissing-declarations doesn't work millerp at canb dot auug dot org dot au
                   ` (3 preceding siblings ...)
  2004-07-07 14:39 ` pinskia at gcc dot gnu dot org
@ 2004-07-08  0:03 ` millerp at canb dot auug dot org dot au
  2004-07-08  0:08 ` pinskia at gcc dot gnu dot org
  2004-07-08  1:57 ` millerp at canb dot auug dot org dot au
  6 siblings, 0 replies; 8+ messages in thread
From: millerp at canb dot auug dot org dot au @ 2004-07-08  0:03 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From millerp at canb dot auug dot org dot au  2004-07-08 00:02 -------
This warning remains useful in C++ because if you change the prototype but not
the definition (or vice versa) you get link time errors instead of compile time
warnings.

For example:
Header file reads
void function(int);
and function defintion matches.  Everything compiles and links.
Now you decide that the "int" is an old C hangover and you change the
*definition* to
void function(bool)
but you -> forget <- to change the header file.  Everything compiles, but the
linker throws an error at every point that "void function(int)" is called,
because it no longer exists.

Ditto for the other way around.

In gcc, you get a compiler warning (or an error in my case, I use -Werror) but
in C++ you get *nothing* until it's time to link.  While you do eventually get
an error, I feel that it is _way_ too late in the process.  The compiler has all
the information to warn (error) much earlier; gcc does, but g++ doesn't.

I'm not talking about generating the correct code, I'm talking about telling the
user something is wrong as early as the tool chain can possibly do so.


-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |UNCONFIRMED
         Resolution|DUPLICATE                   |


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


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug c++/16402] g++ -Wmissing-declarations doesn't work
  2004-07-07  8:24 [Bug c++/16402] New: g++ -Wmissing-declarations doesn't work millerp at canb dot auug dot org dot au
                   ` (4 preceding siblings ...)
  2004-07-08  0:03 ` millerp at canb dot auug dot org dot au
@ 2004-07-08  0:08 ` pinskia at gcc dot gnu dot org
  2004-07-08  1:57 ` millerp at canb dot auug dot org dot au
  6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-07-08  0:08 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2004-07-08 00:08 -------
Sorry but read the whole of PR 8076, this is not very useful as STL depends on stuff like this.

*** This bug has been marked as a duplicate of 8076 ***

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |DUPLICATE


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


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug c++/16402] g++ -Wmissing-declarations doesn't work
  2004-07-07  8:24 [Bug c++/16402] New: g++ -Wmissing-declarations doesn't work millerp at canb dot auug dot org dot au
                   ` (5 preceding siblings ...)
  2004-07-08  0:08 ` pinskia at gcc dot gnu dot org
@ 2004-07-08  1:57 ` millerp at canb dot auug dot org dot au
  6 siblings, 0 replies; 8+ messages in thread
From: millerp at canb dot auug dot org dot au @ 2004-07-08  1:57 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From millerp at canb dot auug dot org dot au  2004-07-08 01:57 -------
OK, I've read all of 8076 and I think folks have missed the point.  You have to
look at it from the point of view of an author who is truly fussy about header
files (if you aren't, you don't turn on this warning).

On the subject of overloading: I realize that overloading is possible in C++. 
If I turn this warning on, I'm saying I _want_ to _know_ when my header files
fail to have declarations for ALL my functions (and ALL includes all
overloadings, too).  That means I expect that there will be a declaration in
scope for all of the possible overloadings, and I want to know when this isn't
the case.  Just to be clear: I want the warning for non-overloaded functions,
too.  All means all.

On the subject of code correctness: if there isn't the full set of declaratuions
in scope when an overloading is called, there is the possibility of the compiler
generating a call to the wrong one.  It's not the compiler's fault, but the
chances of the user making this mistake is reduced with this warning, because
the compiler can tell the user when there is a definition with no corresponding
declaration, impling that there is no declaration in the header file the caller
is supposed to have included.

>From this perspective -Wmisoverloading and -Wmissing-declarations are synonyms.

On the subject of inline declarations: this is the author saying "both interface
and implementation right here" so I feel that the warning could be legitimately
suppressed for inline declarations (in both gcc and g++).

On the subject of STL: the implementation distributed with libstdc++ is hardly
the poster child for good coding practice, so I'm not convinced by any such
argument (except as a pragmatic transitional issue).  BUT this can be solved by
not issuing the warning for system header files, as is done for some other
warnings.  This would make the Scott Meyers warnings more useful, too.

-- 


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


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2004-07-08  1:57 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-07-07  8:24 [Bug c++/16402] New: g++ -Wmissing-declarations doesn't work millerp at canb dot auug dot org dot au
2004-07-07 11:06 ` [Bug c++/16402] " giovannibajo at libero dot it
2004-07-07 12:21 ` millerp at canb dot auug dot org dot au
2004-07-07 13:04 ` bangerth at dealii dot org
2004-07-07 14:39 ` pinskia at gcc dot gnu dot org
2004-07-08  0:03 ` millerp at canb dot auug dot org dot au
2004-07-08  0:08 ` pinskia at gcc dot gnu dot org
2004-07-08  1:57 ` millerp at canb dot auug dot org dot au

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).