-
Notifications
You must be signed in to change notification settings - Fork 14.5k
Description
In the folowing code
int foo1(int x) {
return exp(x);
}
int foo2(int x) {
return erfc(x);
}
int foo3(int x) {
return unknown_function(x);
}
Clang diagnoses:
warning: implicitly declaring library function 'exp' with type 'double (double)' [-Wimplicit-function-declaration]
warning: implicitly declaring library function 'erfc' with type 'double (double)' [-Wimplicit-function-declaration]
warning: implicit declaration of function 'unknown_function' [-Wimplicit-function-declaration]
(https://godbolt.org/z/zq4jsnfnh)
Clang assumes the standard-mandated function declaration with type double (double)
in both cases. This is fine for exp
, however it can be a bit surprising for erfc
which does not exist in C89.
In C89, an implicitly declared function is a variadic function returning int
. I think (as a non-native English speaker), the current warning can possibly be interpreted as "the function was implicitly declared (as in K&R C), in contrast to the standard library function that is declared with type 'double (double)". I think a wording like "implicitly declaring library function 'erfc', assuming standard-mandated type 'double (double)' instead" would be much clearer (for both cases), as it would more clearly communicate what Clang actually does generate.
The improved wording would also be suitable for more modern standard versions.
This issue came up as a side note in a mastodon discussion. @AaronBallman asked me to report this as an issue.