[Freeciv-tickets] [freeciv] #43863: Configure script test for at_quick_exit (C11 feature) causes undesirable -Wimplicit-function-declaration error on macOS

Zurück zum Archiv-Index
OSDN Ticket System norep****@osdn*****
Mon Feb 14 14:06:25 JST 2022


#43863: Configure script test for at_quick_exit (C11 feature) causes undesirable -Wimplicit-function-declaration error on macOS

  Open Date: 2022-02-14 06:22
Last Update: 2022-02-14 07:06

URL for this Ticket:
    https://osdn.net//projects/freeciv/ticket/43863
RSS feed for this Ticket:
    https://osdn.net/ticket/ticket_rss.php?group_id=12505&tid=43863

---------------------------------------------------------------------

Last Changes/Comment on this Ticket:
2022-02-14 07:06 Updated by: cazfi

Comment:

Well, this sort of works as intendet. When at_quick_exit() isn't declared in <stdlib.h>, this compile (+link) test fails indicating that the at_quick_exit() isn't available. I hope your whitelisting does not change that (well, the linking step should fail in any case).
But I guess the problem is in that "elevated -Wimplicit-function-declaration errors to the *user's attention*." So configure checks relying on getting implicit-function-declaration error as means to detecting if a function is declared are problematic. I think we have more of those, though not necessarily ones that are supposed to fail on macOS.


---------------------------------------------------------------------
Ticket Status:

      Reporter: jdlh
         Owner: (None)
          Type: Bugs
        Status: Open
      Priority: 4
     MileStone: (None)
     Component: Bootstrap
      Severity: 5 - Medium
    Resolution: None
---------------------------------------------------------------------

Ticket details:

A configuration macro checks for C11 language feature at_quick_exit() by creating a simple C program which, when compiled on macOS via MacPorts, causes an undesirable -Wimplicit-function-declaration error. This is acceptable, but not ideal. It would be better for macOS and the macPorts distribution if the configuration macro used feature testing like __has_builtin instead. 
The macro causing the error is FC_C11_AT_QUICK_EXIT, in m4/c11.m4:32-51. It tests for a C2011 language standard feature by checking for the existence of an at_quick_exit() function. The specific Autoconf macros running the test are AC_LINK_IFELSE and AC_LANG_PROGRAM. The test program expands to:
#include <stdlib.h>
static void func(void)
{}

int
main (void)
{
 at_quick_exit(func);
  ;
  return 0;
}
Note that this code does #include <stdlib.h>, the file which should declare at_quick_exit() . Thus the test code tries to have explicit, not implicit, function declaration. However, the compiler (and/or the corresponding macOS SDK) does not support the feature, so that version of stdlib.h does not declare the function. The result is that the compiler thinks the program is implicitly defining the function. It raises a -Wimplicit-function-declaration warning.
-Wimplicit-function-declaration warnings are undesirable when compiling Freeciv on macOS. 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. 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. However, MacPorts has a whitelist mechanism for functions which are not supported on certain macOS versions. The function used in Freeciv,  at_quick_exit(), is now on that whitelist. See MacPorts ticket #64550 freec****@2*****: at_quick_exit gives -Wimplicit-function-declaration warning, false positive. Thus for now, this configuration macro is not a problem for Freeciv in MacPorts. In the long term, however, it would be helpful if Freeciv could change the configuration macro so that it does not cause a -Wimplicit-function-declaration error.
What would be a better alternative?  For clang version 11 and later, one alternative is to use the extensions which the compiler provides for testing which features are available. For example, __has_builtin. I have not investigated if gcc has a similar extension, nor how to reconcile that kind of a feature test with what Autoconf offers, and what older compilers support.
Another occurrence of a -Wimplicit-function-declaration, generated by Freeciv's configuration scripts, comes from missing #includes. That was the subject of #43737. It has been fixed. 

-- 
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/43863
RSS feed for this Ticket:
    https://osdn.net/ticket/ticket_rss.php?group_id=12505&tid=43863



More information about the Freeciv-tickets mailing list
Zurück zum Archiv-Index