This is a draft enhancement request to g++, a spec for an option, but I haven't used C++ much so I figured it might be best to ask for review of the spec first. In particular, I don't know what kind of code exists out there, hopefully someone can tell me if I've messed up.
I'd like a -Wmissing-interface warning which attempts to warn me if my library implementation (.c file) defines a publicly accessible symbol - or at least function - which is not declared in the interface (.h file). This is similar to Bug 8076 (-Wmissing-declarations) at http://gcc.gnu.org/bugzilla/show_bug.cgi?id=8076 but the dismissal there seems to miss the point. For C, gcc -Wmissing-declarations comes close. So if you wish, consider this a request to change its spec. (That is my preference, but I'll call it -Wmissing-interface here to keep things straight.) The -Wmissing-interface option is intended to notice several problems: - forgot to include the header with the interface being implemented. - forgot to declare the function in a header. - mismatch between declaration and definition. Currently C gives an error, but C++ silently ignores it. It can either fail at link time (which can be irritatingly late with big packages), or call the wrong function if there is another function with the same name. - a function (or variable?) should be static. Differences from -Wmissing-declarations and replies to Bug 8076: - Overloading: Ignore the problem, except in the doc or warning text. Overloading is why such a warning is important in g++, but technically it can be treated as a side issue. That is, the decision to trigger the warning is unrelated to overloading. It should just check if the (non-static, non-inline) function actually being defined has been declared. Once the warning is triggered, it could say if there is overloading. But it'd be enough to mention in the documentation that in C++, the problem may be prototype mismatch. That simpler way might even be better: The C++ warnings can be too verbose already for my taste. - (Semantic) inline functions: Do not warn, at least in usual cases. I see no semantic difference between C and C++ there. Both languages can have inline functions in both .c and .h files. The difference is mainly in the syntax to specify inlines' various semantics. E.g. in C++, functions with bodies in class bodies are implicitly inline. Admittedly the differences between inline in C++, GNU C and C99 has me confused. I guess the correct spec is, "it should not warn about common and recommended ways to define and declare publicly available inline functions, in whatever language/dialect is being compiled". Not sure if that translates to "never warn about inlines" or something more complicated. Or if there are GNU extensions which affect the issue. I don't think #pragma interface / implementation does, but how about __attribute__((noinline))? - Difference C/C++ in that calls to undeclared/unprototyped functions are legal in C: Yes, that's why -Wimplicit and -Wstrict-prototypes do not make sense for C++, not why -Wmissing-declarations does not. C and C++ programs just fail in different ways. A C program can call the function with wrong calling conventions. A C++ program will either fail to link or, if there is an overloaded function, will call another function than intended. - Variables: Maybe -Wmissing-interface should also warn about non-static, non-predeclared variables, but I don't know if that's feasible in C which supports code like /* NOT 'extern' */ int foo; // in .h file int foo; // in .c file I guess a -Wno-missing-variable-interface would be needed to shut up such code in third-party libraries, if nothing else. For system libraries, I assume the default -Wno-system-headers takes care of the problem. Code snippets: void A(void) {} // Warning. extern void B(int); void B(void) {} // Warning in C++, error in C. inline void C(void) {} // No warning, I think? static void D(void) {} // No warning. static inline void E(void) {} // No warning. extern inline void F(void) {} // No C warning. Don't know C++. extern void G(void); void G(void) {} // No warning. -- Hallvard _______________________________________________ help-gplusplus mailing list help-gplusplus@gnu.org http://lists.gnu.org/mailman/listinfo/help-gplusplus