Possible bug in CLang 3.7.1 / 3.8.0

Hello

Here is a test program:

#include <string.h>

int main()
{
  (void)strlcpy;
  return 0;
}

When I compile it using clang 3.6 compiler reports an error:

$ /usr/bin/clang-3.6 str.c -o str
str.c:5:9: error: use of undeclared identifier 'strlcpy'; did you mean
'struct'?

str.c:5:9: error: expected expression
2 errors generated.

Its OK, this is an expected behavior.

But newer versions of CLang somehow manage to build this program:

$ /usr/local/bin/clang-3.7 str.c -o str

str.c:5:9: warning: implicitly declaring library function 'strlcpy'
with type 'unsigned long (char *, const char *, unsigned
long)'

str.c:5:9: note: include the header <string.h> or explicitly provide a
declaration for 'strlcpy'

1 warning generated.

$ ./str 

$ /usr/local/bin/clang-3.8 str.c -o str

str.c:5:9: warning: implicitly declaring library function 'strlcpy'
with type 'unsigned long (char *, const char *, unsigned
long)' [-Wimplicit-function-declaration]

str.c:5:9: note: include the header <string.h> or explicitly provide a
declaration for 'strlcpy' 1 warning generated.

First of all <string.h> is already included. Also there is no strlcpy
procedure on this system at all (Ubuntu Linux 14.04 x64). Thus this
program should not compile.

It seems to be a serious bug since projects that use Autotools rely on
clang 3.6 behaviour while checking weather current system has strlcpy
procedure.

Or maybe I just don't understand something?

I can confirm this behavior change between 3.6 and 3.7.0. gcc-4.9 and 5.2.1 behave the same way as clang-3.6.

This does seem bogus. Not just for strlcpy, but for any of the recognized stdlib functions.

E.g. without any includes:
int main() {
(void)strcpy;
return 0;
}

gcc fails, and emits:

bar.c:2:9: error: ‘strcpy’ undeclared (first use in this function)

clang succeeds, and emits:

bar.c:2:9: warning: implicitly declaring library function ‘strcpy’ with type ‘char *(char *, const char *)’ [-Wimplicit-function-declaration]

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.

That is, I’d expect the behavior of using strcpy (or strncpy, or any of the others) to be the same as these:

OK (in both gcc and clang):
int main() {
frobnotz(5);
(void)frobnotz;
}

Error (in both gcc and clang):

int main() {
(void)frobnotz;

}