extern-inline.m4 4.9 KB

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