Bug 57574 - -std=c99 inline function incorrectly has external linkage with prior static declaration
Summary: -std=c99 inline function incorrectly has external linkage with prior static d...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c (show other bugs)
Version: 4.8.0
: P3 normal
Target Milestone: 4.9.0
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-06-09 23:45 UTC by Szabolcs Nagy
Modified: 2019-06-14 18:16 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Szabolcs Nagy 2013-06-09 23:45:17 UTC
gcc emits incorrect warning for inline function with internal linkage:

$ cat example.c
static int n;
static inline int f(void);
inline int f(void) {return n;}
int g(){return f();}

$ gcc-4.8 -std=c99 -c example.c 
example.c:3:28: warning: 'n' is static but used in inline function 'f' which is not static [enabled by default]
 inline int f(void) {return n;}
                            ^
$ nm example.o
         U f
00000000 T g
00000000 b n

according to C99 6.2.2p4 the linkage of an identifier
is determined by the prior declaration
(internal in this case, inline does not change that)

referencing static objects from an inline definition
only violates the constraint in C99 6.7.4p3 if the
function has external linkage
(so the diagnostic is unjustified)

it seems from the warning that gcc thinks that f
is not static, this can break code:
the inline definition of f does not provide an
external definition and if the compiler choose
not to inline then the code has undefined f symbol
if the compiler thinks f has external linkage
(as demonstrated by nm above)
Comment 1 Joseph S. Myers 2013-11-29 01:30:45 UTC
Author: jsm28
Date: Fri Nov 29 01:30:42 2013
New Revision: 205506

URL: http://gcc.gnu.org/viewcvs?rev=205506&root=gcc&view=rev
Log:
	PR c/57574
c:
	* c-decl.c (merge_decls): Clear DECL_EXTERNAL for a definition of
	an inline function following a static declaration.

testsuite:
	* gcc.dg/inline-35.c: New test.

Added:
    trunk/gcc/testsuite/gcc.dg/inline-35.c
Modified:
    trunk/gcc/c/ChangeLog
    trunk/gcc/c/c-decl.c
    trunk/gcc/testsuite/ChangeLog
Comment 2 Joseph S. Myers 2013-11-29 01:32:13 UTC
Fixed for 4.9.