<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
</head>
<body>
<p>For the actual issue I'm debugging, see
<a class="moz-txt-link-freetext" href="https://github.com/shadow/shadow/issues/717">https://github.com/shadow/shadow/issues/717</a>. Following is a
simplified repro.</p>
<p>I have a source file:</p>
<p><tt>-------------------------------<br>
#include <stdio.h></tt><tt><br>
</tt><tt><br>
</tt><tt>__extern_inline</tt><tt><br>
</tt><tt>void foo() {</tt><tt><br>
</tt><tt> printf("extern inline\n");</tt><tt><br>
</tt><tt>}</tt><tt><br>
</tt><tt><br>
</tt><tt>static int i = 0;</tt><tt><br>
</tt><tt><br>
</tt><tt>void foo() {</tt><tt><br>
</tt><tt> printf("not inline %d\n", i);</tt><tt><br>
</tt><tt>}</tt><tt><br>
</tt><tt><br>
</tt><tt>int main(int argc, char **argv) {</tt><tt><br>
</tt><tt> foo();</tt><tt><br>
</tt><tt> return 0;</tt><tt><br>
</tt><tt>}</tt><tt><br>
</tt><tt>-------------------------------</tt></p>
<p>When I compile and run I get:</p>
<p><tt><tt>-------------------------------</tt><br>
$ clang -Wall -Wstatic-in-inline inline.c </tt><tt><br>
</tt><tt>inline.c:11:31: warning: static variable 'i' is used in
an inline function with</tt><tt><br>
</tt><tt> external linkage [-Wstatic-in-inline]</tt><tt><br>
</tt><tt> printf("not inline %d\n", i);</tt><tt><br>
</tt><tt> ^</tt><tt><br>
</tt><tt>inline.c:8:12: note: 'i' declared here</tt><tt><br>
</tt><tt>static int i = 0;</tt><tt><br>
</tt><tt> ^</tt><tt><br>
</tt><tt>$ ./a.out</tt><tt><br>
</tt><tt>not inline 0<br>
-------------------------------</tt>
</p>
<p>Q1: Ignoring the static variable reference for the moment, is it
actually safe to have both an inline and non-inline definition?
For a compilation unit that sees both, is there any guarantee
about which definition it will get? (Both clang and gcc give a
redefinition error if I use "extern inline" instead of
__extern_inline; I'm reproducing a situation I'm getting from
pthread.h and stdio.h. I can't find any documentation about the
semantics of __extern_inline)</p>
<p>Q2: Is it a clang bug that -Wstatic-in-inline triggers when the
*non-inline* definition is the one that references the static
variable? i.e. can I safely ignore the warning in this case?</p>
<p>Thanks!</p>
<p>-Jim<br>
</p>
<p>P.S. Some additional diagnostics:</p>
<p><tt>$ clang -v<br>
clang version 6.0.0-1ubuntu2 (tags/RELEASE_600/final)<br>
Target: x86_64-pc-linux-gnu<br>
Thread model: posix<br>
InstalledDir: /usr/bin<br>
Found candidate GCC installation:
/usr/bin/../lib/gcc/i686-linux-gnu/8<br>
Found candidate GCC installation:
/usr/bin/../lib/gcc/x86_64-linux-gnu/7<br>
Found candidate GCC installation:
/usr/bin/../lib/gcc/x86_64-linux-gnu/7.4.0<br>
Found candidate GCC installation:
/usr/bin/../lib/gcc/x86_64-linux-gnu/8<br>
Found candidate GCC installation: /usr/lib/gcc/i686-linux-gnu/8<br>
Found candidate GCC installation:
/usr/lib/gcc/x86_64-linux-gnu/7<br>
Found candidate GCC installation:
/usr/lib/gcc/x86_64-linux-gnu/7.4.0<br>
Found candidate GCC installation:
/usr/lib/gcc/x86_64-linux-gnu/8<br>
Selected GCC installation:
/usr/bin/../lib/gcc/x86_64-linux-gnu/7.4.0<br>
Candidate multilib: .;@m64<br>
Selected multilib: .;@m64</tt></p>
<p><tt>$ clang -E inline.c<br>
<snip</tt><tt>><br>
extern __inline __attribute__ ((__gnu_inline__))</tt><tt><br>
</tt><tt>void foo() {</tt><tt><br>
</tt><tt> printf("extern inline\n");</tt><tt><br>
</tt><tt>}<br>
</tt><tt><snip></tt><br>
<font face="Courier New, Courier, monospace"></font></p>
</body>
</html>