Debian Codegraph @

m4/extern-inline.m4

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