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

Re: PATCH RFA: Support -Wmissing-declarations in C++

Gabriel Dos Reis <> writes:

> Ian Lance Taylor <> writes:
> | Currently -Wmissing-declarations only works for C.  But it makes just
> | as much sense for C++ as it does for C.  This patch adds support for
> | -Wmissing-declarations in C++.
> I don't think it makes that much sense for C++, let alone as much sense.
> In C++, if you don't have a declaration in scope, it is a hard error.
> In C, the situation is different, which led to -Wmissing-declarations.
> -Wmissing-declarations embodies C ways of viewing and programming,
> that are counter-idiomatic in C++.
> Furthermore, a function can be declared only once at class scope.  The
> artificial dissymmetry that this switch will introduce for such a
> fundamental notion as class in C++ is a strong hint that this switch
> is best left for the C front-end.

I disagree.  It makes sense in the C++ world too, though I agree that
it is not as important in C.  This option applies only to global
functions, not to classes, nor to functions declared within classes
(aka methods).

You have misstated the reason for the warning.  I actually suggested
this option originally, for C, back in 1990 or so.  The case this
warning is for is:

  extern int foo();
  #include "foo.h"
  int bar() { return foo(); }
  double foo() { return 0; }

In other words: forgot to include "foo.h", and then somebody
changed the definition of foo() without updating the declaration in

This does not happen as often in C++ as it does in C, but it can and
does happen.  And it did in fact happen in some C++ code here, which
is why I thought to make the option work for C++.

Note that this option is not turned on by -Wall.  It is entirely
optional.  Since it makes just as much sense for C++ as for C, I see
no reason not to enable it for C++.


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