Bug 54113 - -Wmissing-prototypes produces false alarms for C99 inline functions
Summary: -Wmissing-prototypes produces false alarms for C99 inline functions
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c (show other bugs)
Version: 4.7.1
: P3 normal
Target Milestone: ---
Assignee: Marek Polacek
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-07-28 13:47 UTC by Paul Eggert
Modified: 2017-09-07 02:55 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2013-12-04 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Paul Eggert 2012-07-28 13:47:28 UTC
-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.
Comment 1 Paul Eggert 2012-08-14 04:08:17 UTC
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.
Comment 2 Marek Polacek 2013-12-04 17:00:12 UTC
I have a patch for disabling the diagnostic  for inline functions in C99 mode.
Comment 3 Marek Polacek 2013-12-04 21:15:34 UTC
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
Comment 4 Marek Polacek 2013-12-04 21:18:19 UTC
Fixed on trunk.
Comment 5 Eric Gallager 2017-09-07 02:55:07 UTC
(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\"") \
     ^~~~~~~