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

erh+gcc at nimenees dot com gcc-bugzilla@gcc.gnu.org
Fri Mar 5 21:15:00 GMT 2010


(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 <<EOF
    void myfunc(const char *arg1)
    {
        /* do stuff with arg1 */
    }
    EOF
    g++ -Wmissing-prototypes -c foo.cpp

This complains with the message:
cc1plus: warning: command line option "-Wmissing-prototypes" is valid for
Ada/C/ObjC but not for C++

This can lead to mismatches between the function that callers call, based on
the header file and what is actually implemented.  For example, say foo.h
contains:
void myfunc(char *arg1);

Theoretically, this problem would be caught at link time, but depending on how
development is occurring that can easily be days later.  For instance, if
myfunc() is part of a library, the problem might not be noticed until the
library is published and other software starts trying to use it.

It could be argued that the library should have a unit test that uses the
function, but only in a perfect world would that be true for all development. 
(and in a perfect world, we wouldn't need warnings anyway! :) )

Even with a unit test, the fact that this warning doesn't work means that
rather than the developer having a quick turn around between when he changes
something and when the problem becomes apparent, that being the time it takes
to compile just that one file, he instead would need to go through the whole
rest of his build, and link the unit test, and finally run the unit test.  That
makes development unnecessarily inefficient.


-- 
           Summary: -Wmissing-prototypes doesn't work in C++ mode
           Product: gcc
           Version: 4.3.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: erh+gcc at nimenees dot com
 GCC build triplet: gcc version 4.3.2 (Ubuntu 4.3.2-1ubuntu12)
GCC target triplet: i486-linux-gnu


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



More information about the Gcc-bugs mailing list