How to suppress -Wimplicit-function-declaration warning, if <stdlib.h> really does not have the declaration?

Joshua Root jmr at macports.org
Wed Jan 26 10:59:51 UTC 2022


On 2022-1-26 18:43 , Jim DeLaHunt wrote:
> When I attempt to compile it with clang as provided by XCode 11.2.1 
> (11B5000) on macOS 10.14.6 Mojave, I get the 
> -Wimplicit-function-declaration warning:
> 
> % /usr/bin/clang -o conftest -std=c11 -I/opt/local/include -Werror -Wall -Wpointer-arith -Wcast-align -Wno-tautological-compare -L/opt/local/libexec/qt5/lib -L/opt/local/lib conftest.c  -liconv
> conftest.c:99:2: error: implicit declaration of function 'at_quick_exit' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
>   at_quick_exit(func);
>   ^
> 1 error generated.
> %
> 
> Most of the instructions about resolving -Wimplicit-function-declaration 
> warning[3] assume code which does not include the appropriate system 
> header, and suggest adding the system header.
> 
> But this code does have the right system header: <stdlib.h>. It looks 
> like that header does not include a declaration of at_quick_exit(). Thus 
> the call to at_quick_exit() in the main function is in fact an implicit 
> function declaration, and the warning is appropriate. Let's assume that 
> is correct; that this compiler and its includes and libraries really do 
> not have at_quick_exit(). Maybe some other compilers or versions do have 
> it. And let's assume that this configure code fails correctly, and thus 
> configures correctly in the absence of at_quick_exit().

I get the same result on Big Sur. Curious, since at_quick_exit is 
apparently part of the C11 standard.

In any case, we maintain lists of functions that are known not to exist 
on each macOS version, so the warning can be suppressed. They are in the 
ports tree here: 
<https://github.com/macports/macports-ports/tree/master/_resources/port1.0/checks/implicit_function_declaration>

> Is it significant that the error message mentions "C99", when I am 
> passing the compiler the option "-std=c11"?  Have I failed to get the 
> compiler into C11 support mode?

No, the message should really say "C99 and later". (Implicit declaration 
was only allowed in the 1989 standard as a concession to existing 
K&R-style programs; it's been discouraged pretty much forever. It's 
interesting that this error message still carries the assumption that 
you are deliberately trying to use implicit declaration, rather than 
just having made a mistake.)

> How can I patch this code so that it passes where the feature is 
> defined, and fails where the feature is not, and does not result in 
> MacPorts displaying a warning in the main.log file when building the port?

The configure code doesn't look like it needs to be patched at all. It 
should correctly detect whether at_quick_exit is available; the error is 
how autoconf detects that it isn't. All that needs to be done is adding 
at_quick_exit to the appropriate lists of known missing functions, so 
the warning won't be printed by MacPorts base.

- Josh


More information about the macports-dev mailing list