extern-inline.m4 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. dnl 'extern inline' a la ISO C99.
  2. dnl Copyright 2012-2023 Free Software Foundation, Inc.
  3. dnl This file is free software; the Free Software Foundation
  4. dnl gives unlimited permission to copy and/or distribute it,
  5. dnl with or without modifications, as long as this notice is preserved.
  6. AC_DEFUN([gl_EXTERN_INLINE],
  7. [
  8. AC_CACHE_CHECK([whether ctype.h defines __header_inline],
  9. [gl_cv_have___header_inline],
  10. [AC_PREPROC_IFELSE(
  11. [AC_LANG_SOURCE([[#include <ctype.h>
  12. #ifndef __header_inline
  13. #error "<ctype.h> does not define __header_inline"
  14. #endif
  15. ]])],
  16. [gl_cv_have___header_inline=yes],
  17. [gl_cv_have___header_inline=no])])
  18. if test "$gl_cv_have___header_inline" = yes; then
  19. AC_DEFINE([HAVE___HEADER_INLINE], [1],
  20. [Define to 1 if ctype.h defines __header_inline.])
  21. fi
  22. AH_VERBATIM([HAVE___HEADER_INLINE_1],
  23. [/* Please see the Gnulib manual for how to use these macros.
  24. Suppress extern inline with HP-UX cc, as it appears to be broken; see
  25. <https://lists.gnu.org/r/bug-texinfo/2013-02/msg00030.html>.
  26. Suppress extern inline with Sun C in standards-conformance mode, as it
  27. mishandles inline functions that call each other. E.g., for 'inline void f
  28. (void) { } inline void g (void) { f (); }', c99 incorrectly complains
  29. 'reference to static identifier "f" in extern inline function'.
  30. This bug was observed with Oracle Developer Studio 12.6
  31. (Sun C 5.15 SunOS_sparc 2017/05/30).
  32. Suppress extern inline (with or without __attribute__ ((__gnu_inline__)))
  33. on configurations that mistakenly use 'static inline' to implement
  34. functions or macros in standard C headers like <ctype.h>. For example,
  35. if isdigit is mistakenly implemented via a static inline function,
  36. a program containing an extern inline function that calls isdigit
  37. may not work since the C standard prohibits extern inline functions
  38. from calling static functions (ISO C 99 section 6.7.4.(3).
  39. This bug is known to occur on:
  40. OS X 10.8 and earlier; see:
  41. https://lists.gnu.org/r/bug-gnulib/2012-12/msg00023.html
  42. DragonFly; see
  43. http://muscles.dragonflybsd.org/bulk/clang-master-potential/20141111_102002/logs/ah-tty-0.3.12.log
  44. FreeBSD; see:
  45. https://lists.gnu.org/r/bug-gnulib/2014-07/msg00104.html
  46. OS X 10.9 has a macro __header_inline indicating the bug is fixed for C and
  47. for clang but remains for g++; see <https://trac.macports.org/ticket/41033>.
  48. Assume DragonFly and FreeBSD will be similar.
  49. GCC 4.3 and above with -std=c99 or -std=gnu99 implements ISO C99
  50. inline semantics, unless -fgnu89-inline is used. It defines a macro
  51. __GNUC_STDC_INLINE__ to indicate this situation or a macro
  52. __GNUC_GNU_INLINE__ to indicate the opposite situation.
  53. GCC 4.2 with -std=c99 or -std=gnu99 implements the GNU C inline
  54. semantics but warns, unless -fgnu89-inline is used:
  55. warning: C99 inline functions are not supported; using GNU89
  56. warning: to disable this warning use -fgnu89-inline or the gnu_inline function attribute
  57. It defines a macro __GNUC_GNU_INLINE__ to indicate this situation.
  58. */
  59. #if (((defined __APPLE__ && defined __MACH__) \
  60. || defined __DragonFly__ || defined __FreeBSD__) \
  61. && (defined HAVE___HEADER_INLINE \
  62. ? (defined __cplusplus && defined __GNUC_STDC_INLINE__ \
  63. && ! defined __clang__) \
  64. : ((! defined _DONT_USE_CTYPE_INLINE_ \
  65. && (defined __GNUC__ || defined __cplusplus)) \
  66. || (defined _FORTIFY_SOURCE && 0 < _FORTIFY_SOURCE \
  67. && defined __GNUC__ && ! defined __cplusplus))))
  68. # define _GL_EXTERN_INLINE_STDHEADER_BUG
  69. #endif
  70. #if ((__GNUC__ \
  71. ? defined __GNUC_STDC_INLINE__ && __GNUC_STDC_INLINE__ \
  72. : (199901L <= __STDC_VERSION__ \
  73. && !defined __HP_cc \
  74. && !defined __PGI \
  75. && !(defined __SUNPRO_C && __STDC__))) \
  76. && !defined _GL_EXTERN_INLINE_STDHEADER_BUG)
  77. # define _GL_INLINE inline
  78. # define _GL_EXTERN_INLINE extern inline
  79. # define _GL_EXTERN_INLINE_IN_USE
  80. #elif (2 < __GNUC__ + (7 <= __GNUC_MINOR__) && !defined __STRICT_ANSI__ \
  81. && !defined _GL_EXTERN_INLINE_STDHEADER_BUG)
  82. # if defined __GNUC_GNU_INLINE__ && __GNUC_GNU_INLINE__
  83. /* __gnu_inline__ suppresses a GCC 4.2 diagnostic. */
  84. # define _GL_INLINE extern inline __attribute__ ((__gnu_inline__))
  85. # else
  86. # define _GL_INLINE extern inline
  87. # endif
  88. # define _GL_EXTERN_INLINE extern
  89. # define _GL_EXTERN_INLINE_IN_USE
  90. #else
  91. # define _GL_INLINE _GL_UNUSED static
  92. # define _GL_EXTERN_INLINE _GL_UNUSED static
  93. #endif
  94. /* In GCC 4.6 (inclusive) to 5.1 (exclusive),
  95. suppress bogus "no previous prototype for 'FOO'"
  96. and "no previous declaration for 'FOO'" diagnostics,
  97. when FOO is an inline function in the header; see
  98. <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=54113> and
  99. <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63877>. */
  100. #if __GNUC__ == 4 && 6 <= __GNUC_MINOR__
  101. # if defined __GNUC_STDC_INLINE__ && __GNUC_STDC_INLINE__
  102. # define _GL_INLINE_HEADER_CONST_PRAGMA
  103. # else
  104. # define _GL_INLINE_HEADER_CONST_PRAGMA \
  105. _Pragma ("GCC diagnostic ignored \"-Wsuggest-attribute=const\"")
  106. # endif
  107. # define _GL_INLINE_HEADER_BEGIN \
  108. _Pragma ("GCC diagnostic push") \
  109. _Pragma ("GCC diagnostic ignored \"-Wmissing-prototypes\"") \
  110. _Pragma ("GCC diagnostic ignored \"-Wmissing-declarations\"") \
  111. _GL_INLINE_HEADER_CONST_PRAGMA
  112. # define _GL_INLINE_HEADER_END \
  113. _Pragma ("GCC diagnostic pop")
  114. #else
  115. # define _GL_INLINE_HEADER_BEGIN
  116. # define _GL_INLINE_HEADER_END
  117. #endif])
  118. ])