-Wmissing-prototypes produces false alarms for C99-style inline functions. Here's a simple example, taken from <http://www.drdobbs.com/the-new-c-inline-functions/184401540>. Suppose foo.h contains this: inline float square(float x) {return x*x;} inline float cube(float x) {return x*x*x;} and foo.c contains this: #include "foo.h" extern float square(float x); extern float cube(float x); Then the command: gcc -c -Wmissing-prototypes foo.c outputs: In file included from foo.c:1:0: foo.h:1:14: warning: no previous prototype for 'square' [-Wmissing-prototypes] foo.h:2:14: warning: no previous prototype for 'cube' [-Wmissing-prototypes] The diagnostics should not be output, as this is the normal way to use inline functions in C. The simplest way to work around the problem is to avoid the use of -Wmissing-prototypes, but that disables the diagnostic for non-inline functions, where it's useful. To fix this, I suggest that the diagnostic be suppressed for inline functions, at least for C99 mode.
In <http://lists.gnu.org/archive/html/bug-gnulib/2012-08/msg00038.html> Jim Meyering reports that GCC 4.8.0 20120803 issues a different (but still bogus) warning for this program. It reports "error: no previous declaration for 'FOO' [-Werror=missing-declarations]" if FOO is an inline function. This warning should not be emitted either.
I have a patch for disabling the diagnostic for inline functions in C99 mode.
Author: mpolacek Date: Wed Dec 4 21:15:31 2013 New Revision: 205680 URL: http://gcc.gnu.org/viewcvs?rev=205680&root=gcc&view=rev Log: PR c/54113 c/ * c-decl.c (start_function): Don't warn for missing prototype for inline functions. testsuite/ * gcc.dg/pr54113.c: New test. Added: trunk/gcc/testsuite/gcc.dg/pr54113.c Modified: trunk/gcc/c/ChangeLog trunk/gcc/c/c-decl.c trunk/gcc/testsuite/ChangeLog
Fixed on trunk.
(In reply to Paul Eggert from comment #0) > > The simplest way to work around the problem is to avoid > the use of -Wmissing-prototypes, but that disables the > diagnostic for non-inline functions, where it's useful. > Note that this only works for plain C; using diagnostic pragmas (like those expanded from gnulib's _GL_INLINE_HEADER_BEGIN) to suppress -Wmissing-prototypes leads to the following warning in C++: build-gnulib/../config.h:2101:5: warning: option ‘-Wmissing-prototypes’ is valid for C/ObjC but not for C++ [-Wpragmas] _Pragma ("GCC diagnostic ignored \"-Wmissing-prototypes\"") \ ^~~~~~~