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

            Bug ID: 57574
           Summary: -std=c99 inline function incorrectly has external
                    linkage with prior static declaration
           Product: gcc
           Version: 4.8.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: nszabolcs at gmail dot com

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)

Reply via email to