<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Jan 27, 2016 at 3:01 AM, Rainer Gerhards via cfe-users <span dir="ltr"><<a href="mailto:cfe-users@lists.llvm.org" target="_blank">cfe-users@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Hi all,<div><br></div><div>I try to use -Werror -Wall for my project, which includes -Wunused-function.</div><div><br></div><div>Unfortunately, I receive a couple of warnings from library header files which include</div><div><br></div><div>static inline ... func() { ... }</div><div><br></div><div>These functions are indeed often unused, but as of my understanding this should be perfectly fine with static inline functions (they just replace macro definitions in a better way). </div></div></blockquote><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><br></div><div>Am I wrong here? What's the best path to fix this?</div></div></blockquote><div><br></div><div>Ish. They shuold probably just be "inline" without the static.<br><br>static functions are distinct functions per translation unit - so having static functions in headers has a number of problems:<br><br>* The function definitions won't be deduplicated by the linker across object files -> code bloat (larger binaries) & address inequality<br>* This can lead to technical (& undiagnosed) Undefined Behavior due to ODR violations<br><br>Consider the following header:<br><br>static inline void f() { }<br>struct foo {<br>  void g() { f();<br>};<br><br>Include that header in two .cpp files, compile and link the two objects together and the program now violates the ODR<br><br>The violation is in 'g' which is a (non-static, in the sense we're talking about here - though it could be class-static and still reproduce the problem) inline function. Therefore its definition must be the same in every translation unit - by "the same", the C++ standard says the same sequence of tokens (which it is) and that every name lookup finds the same entities (which it doesn't - because 'f' in one translation unit is a distinct 'f' from the other translation unit because of the 'static' keyword)).<br><br>So the assumption is that, generally, file/namespace-scope-static (as opposed to class scoped static, which is a different thing) functions do not go in headers. Or, put another way - static functions are there to be used in the translation unit that contains their definition. So that's why the warning fires on your code & why removing 'static' is a good/reasonable fix to the warning and what it is, tangentially, trying to warn you about.<br><br>Hope that helps,<br>- Dave</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><br></div><div>version: Ubuntu clang version 3.6.2-1 (tags/RELEASE_362/final) (based on LLVM 3.6.2)<br></div><div><br></div><div>Any help is deeply appreciated.</div><span class="HOEnZb"><font color="#888888"><div><br></div><div>Rainer</div></font></span></div>
<br>_______________________________________________<br>
cfe-users mailing list<br>
<a href="mailto:cfe-users@lists.llvm.org">cfe-users@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-users" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-users</a><br>
<br></blockquote></div><br></div></div>