#43737: Configure scripts give needless -Wimplicit-function-declaration errors on macOS Open Date: 2022-01-29 01:15 Last Update: 2022-01-30 00:23 URL for this Ticket: https://osdn.net//projects/freeciv/ticket/43737 RSS feed for this Ticket: https://osdn.net/ticket/ticket_rss.php?group_id=12505&tid=43737 --------------------------------------------------------------------- Last Changes/Comment on this Ticket: 2022-01-30 00:23 Updated by: jdlh Comment: I have looked at this issue in branches master, S3_1, and S3_0. In all of those branches, file m4/x.m4 is no longer present, so does not need to be patched. And, file m4/vsnprintf.m4 appears to be identical in all these branches and in S2_6, so the patch that fixes this file for S2_6 works just as well in the other three branches. I have attached a patch, 0002-Eliminate-needless-Wimplicit-function-declaration-er.patch . It patches m4/vsnprintf.m4 only. I believe that this patch, applied to any of branches master, S3_1, or S3_0, will fix the problem described by this ticket. Here is more detail on what the patch 0002 does. I reconfigured the project in branch master. There were three occurrences of -Wimplicit-function-declaration in the config.log file. The first is related to function at_quick_exit, and is the subject of the other ticket I have alluded to above. The other two occurrences are related to this ticket, and are the following: configure:38800: checking for working vsnprintf configure:38856: /usr/bin/clang -o conftest -g -O2 -I/opt/local/include -DLOCALEDIR="\"${datarootdir}/locale\"" -DBINDIR="\"${exec_prefix}/bin\"" -L/opt/local/libexec/qt5/lib -L/opt/local/lib conftest.c -liconv -pthread >&5 conftest.c:183:5: warning: implicitly declaring library function 'exit' with type 'void (int) __attribute__((noreturn))' [-Wimplicit-function-declaration] exit(1); ^ conftest.c:183:5: note: include the header <stdlib.h> or explicitly provide a declaration for 'exit' conftest.c:192:7: warning: implicitly declaring library function 'strcmp' with type 'int (const char *, const char *)' [-Wimplicit-function-declaration] if (strcmp(buffer, "1234")) ^ conftest.c:192:7: note: include the header <string.h> or explicitly provide a declaration for 'strcmp' 2 warnings generated. configure:38856: $? = 0 configure:38856: ./conftest configure:38856: $? = 0 configure:38867: result: yes These errors arise when the script in m4/vsnprintf.m4 compiling its configuration check program. The program lacks #include <stdlib.h>, so the function exit() is not declared. It also lacks #include <string.h>, so the function strcmp() is not declared. This patch adds these two #includes to the script, so that they are in the configure check program. With the patch applied, reconfigure the project. Now the lines labelled conftest.c:183:5 and conftest.c:192:7 no longer appear in config.log. I suggest definitely applying this patch to master, S3_1, and S2_6. I don't think it needs to be a freeze exception for S3_0. Once Freeciv 3.0.0 is released, then apply the patch to S3_0 so that it appears in Freeciv 3.0.1. I will apply the equivalent of patch 0001 to freeciv 2.6.6 via MacPorts mechanisms, and the equivalent of patch 0002 to freeciv 3.0.0 when it ships. Freeciv will compile and run fine in MacPorts if we apply these patches at the MacPorts level. However, in the long run it would be better to fix these configuration scripts upstream. --------------------------------------------------------------------- Ticket Status: Reporter: jdlh Owner: (None) Type: Bugs Status: Open Priority: 5 - Medium MileStone: 3.0.1 Component: Bootstrap Severity: 4 Resolution: None --------------------------------------------------------------------- Ticket details: Three configuration macros create simple C programs which, when compiled on macOS, needlessly cause -Wimplicit-function-declaration errors. Adding #include <stdlib.h> and #include <stdlib.h> to those macros prevents those warnings, without changing what the configuration macros are trying to check for. macOS's Xcode compilers (based on clang) have applied -Werror and -Wimplicit-function-declaration options since about 2019. They do this as part of support for the Apple ARM architecture CPUs. On those CPUs, the calling sequence for varargs functions differ from the calling sequence for functions with a fixed number of parameters. If a function prototype is not declared, the compiler is unable to guess which kind of args the function uses. This means that the programs generated by the configuration macros may, on macOS, fail to compile, instead of compiling and running. This means in turn that the macros may get the wrong result about the system's capabilities, and so they may configure Freeciv incorrectly. Also, defining functions without explicitly declaring them has been illegal C language since about the late 1980s, but many compilers have tolerated it. Thus, compiler errors have not been a reason to clean up these macros — until now. For more on the Xcode compiler issue, see the writeup in the MacPorts wiki at https://trac.macports.org/wiki/WimplicitFunctionDeclaration . Since 2021, the MacPorts distribution software has specifically elevated -Wimplicit-function-declaration errors to the user's attention. As an interim measure, the MacPorts distribution can patch Freeciv to prevent these errors. See MacPorts ticket #64551 freec****@2*****: X11 config tests gives -Wimplicit-function-declaration warning on exit, strcmp. In the long term, it helps MacPorts to distribute Freeciv if Freeciv can prevent these warnings upstream from MacPorts. The fix for all but one of these errors is simple: patch m4/x.m4 to add one line in each of two places, and patch m4/vsnprintf.m4 to add two lines in one place. I will attach patches to this ticket, which I have tested on the S2_6 branch, version 2.6.6 code. I will also test against the other branches, and produce different patches for those branches if necessary. Another occurrence of a -Wimplicit-function-declaration, generated by Freeciv's configuration scripts, comes from a check on c11 functionality. It is not a matter of a missing #include. This will be the subject of a separate ticket. -- Ticket information of Freeciv project Freeciv Project is hosted on OSDN Project URL: https://osdn.net/projects/freeciv/ OSDN: https://osdn.net URL for this Ticket: https://osdn.net/projects/freeciv/ticket/43737 RSS feed for this Ticket: https://osdn.net/ticket/ticket_rss.php?group_id=12505&tid=43737