<div dir="ltr">This does seem bogus. Not just for strlcpy, but for any of the recognized stdlib functions.<div><br></div><div>E.g. without any includes:</div><span style="font-size:12.8px">  int main() </span><span style="font-size:12.8px">{</span><br style="font-size:12.8px"><span style="font-size:12.8px">    (void)strcpy;</span><br style="font-size:12.8px"><span style="font-size:12.8px">    return 0;</span><br style="font-size:12.8px"><span style="font-size:12.8px">  }</span><br><div><br></div><div>gcc fails, and emits:</div><div><div><span style="font-size:12.8px">bar.c:2:9: error: ‘strcpy’ undeclared (first use in this function)</span></div><div><br></div><div>clang succeeds, and emits:</div><div><div>bar.c:2:9: warning: implicitly declaring library function 'strcpy' with type 'char *(char *, const char *)' [-Wimplicit-function-declaration]</div></div><div><br></div><div>GCC's behavior there seems more sensible -- I'd expect the implicit declarations to only be introduced in the compilation unit when an implicit declaration would be made for a non-stdlib function. That is to say, when you're doing a function call, not when using it as a value.</div><div><br></div></div><div>That is, I'd expect the behavior of using strcpy (or strncpy, or any of the others) to be the same as these:</div><div><br></div><div>OK (in both gcc and clang):</div><div>  int main() {</div><div>    frobnotz(5);</div><div>    (void)frobnotz;</div><div>  }</div><div><br></div><div>Error (in both gcc and clang):</div><div><div>  int main() {</div><div>    (void)frobnotz;<br></div><div>  }</div></div><div><br></div><div><br></div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Mar 25, 2016 at 6:26 AM, Aleksander Alekseev via cfe-dev <span dir="ltr"><<a href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@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">Hello<br>
<br>
Here is a test program:<br>
<br>
```<br>
#include <string.h><br>
<br>
int main()<br>
{<br>
  (void)strlcpy;<br>
  return 0;<br>
}<br>
```<br>
<br>
When I compile it using clang 3.6 compiler reports an error:<br>
<br>
```<br>
$ /usr/bin/clang-3.6 str.c -o str<br>
str.c:5:9: error: use of undeclared identifier 'strlcpy'; did you mean<br>
'struct'?<br>
<br>
str.c:5:9: error: expected expression<br>
2 errors generated.<br>
```<br>
<br>
Its OK, this is an expected behavior.<br>
<br>
But newer versions of CLang somehow manage to build this program:<br>
<br>
```<br>
$ /usr/local/bin/clang-3.7 str.c -o str<br>
<br>
str.c:5:9: warning: implicitly declaring library function 'strlcpy'<br>
with type 'unsigned long (char *, const char *, unsigned<br>
long)'<br>
<br>
str.c:5:9: note: include the header <string.h> or explicitly provide a<br>
declaration for 'strlcpy'<br>
<br>
1 warning generated.<br>
<br>
$ ./str<br>
<br>
$ /usr/local/bin/clang-3.8 str.c -o str<br>
<br>
str.c:5:9: warning: implicitly declaring library function 'strlcpy'<br>
with type 'unsigned long (char *, const char *, unsigned<br>
long)' [-Wimplicit-function-declaration]<br>
<br>
str.c:5:9: note: include the header <string.h> or explicitly provide a<br>
declaration for 'strlcpy' 1 warning generated.<br>
```<br>
<br>
First of all <string.h> is already included. Also there is no strlcpy<br>
procedure on this system at all (Ubuntu Linux 14.04 x64). Thus this<br>
program should not compile.<br>
<br>
It seems to be a serious bug since projects that use Autotools rely on<br>
clang 3.6 behaviour while checking weather current system has strlcpy<br>
procedure.<br>
<br>
Or maybe I just don't understand something?<br>
<span class="HOEnZb"><font color="#888888"><br>
--<br>
Best regards,<br>
Aleksander Alekseev<br>
<a href="http://eax.me/" rel="noreferrer" target="_blank">http://eax.me/</a><br>
_______________________________________________<br>
cfe-dev mailing list<br>
<a href="mailto:cfe-dev@lists.llvm.org">cfe-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev</a><br>
</font></span></blockquote></div><br></div>