Skip to content

[Clang] improve -Wimplicit-function-declaration wording #146924

@manxorist

Description

@manxorist

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang:diagnosticsNew/improved warning or error message in Clang, but not in clang-tidy or static analyzerquality-of-implementation

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions