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

On Thu, 14 Dec 2006, Ian Lance Taylor wrote:


| > What you have to do is consider how warnings intereacts with idiomatic
| > C++.  Idiomatic C++, means that people use many third-party libraries,
| > and those libraries tend to have their implementations in headers.  A
| > situation that is very different from C.
| I'm trying to sort out what your real objection is.  I know that the
| warning was clearly useful for real code here, and would have avoided
| a real bug if it had been available.
| Suppose I adjust the code so that it does not warn about functions
| explicitly declared inline.  Would that help address your concerns?

My objection stems from looking at how C++ codes are written, and how
programs are composed and the implication of a warning switch like
-Wmissing-declarations (which has lot of ressemblance with -Weffc++).

(1) the switch is based on the assumption that you would have a
    declaration set in one file that people would include in
    implementation files -- pretty standard 101 coding.

(2) That assumption used to hold 20 years ago for C++.  However, it is less
    verified for modern C++.  For good or bad, most of libraries
    come in header files (because they are either templates or inline
    functions) and there no longer is a clear separation between
    implementation and "interfaces" (and those are subject to pretty
    strong ODR requirements, which makes the kind of mistakes you
    would like to prevent very unlikely, but the implementation would
    generate lot of noise).

    Consequently, the premise (1) when mechanically enforced without
    considerations of how modern C++ programs are written will act
    like a virus: it will fired up not only in the implementation
    files that was supposed to be checked, but also in third party
    libraries used as components (because many of them come in header
    files).  [This has been happening for real with -Weffc++.]

    You can reduce the virus effect by not flagging inline functions,
    function templates (whether declared inline of not).

    It is also helpful to consider libraries freely available to see
    how people write codes and how it will affect them.

-- Gaby

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