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)
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
Fixed for 4.9.