Debian Codegraph @

m4/extern-inline.m4

raw
1 # extern-inline.m4
2 # serial 1
3 dnl Copyright 2012-2024 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 the C standard prohibits extern inline functions
47 from calling static functions (ISO C 99 section 6.7.4.(3).
48 This bug is known to occur on:
49
50 OS X 10.8 and earlier; see:
51 https://lists.gnu.org/r/bug-gnulib/2012-12/msg00023.html
52
53 DragonFly; see
54 http://muscles.dragonflybsd.org/bulk/clang-master-potential/20141111_102002/logs/ah-tty-0.3.12.log
55
56 FreeBSD; see:
57 https://lists.gnu.org/r/bug-gnulib/2014-07/msg00104.html
58
59 OS X 10.9 has a macro __header_inline indicating the bug is fixed for C and
60 for clang but remains for g++; see <https://trac.macports.org/ticket/41033>.
61 Assume DragonFly and FreeBSD will be similar.
62
63 GCC 4.3 and above with -std=c99 or -std=gnu99 implements ISO C99
64 inline semantics, unless -fgnu89-inline is used. It defines a macro
65 __GNUC_STDC_INLINE__ to indicate this situation or a macro
66 __GNUC_GNU_INLINE__ to indicate the opposite situation.
67 GCC 4.2 with -std=c99 or -std=gnu99 implements the GNU C inline
68 semantics but warns, unless -fgnu89-inline is used:
69 warning: C99 inline functions are not supported; using GNU89
70 warning: to disable this warning use -fgnu89-inline or the gnu_inline function attribute
71 It defines a macro __GNUC_GNU_INLINE__ to indicate this situation.
72 */
73 #if (((defined __APPLE__ && defined __MACH__) \
74 || defined __DragonFly__ || defined __FreeBSD__) \
75 && (defined HAVE___HEADER_INLINE \
76 ? (defined __cplusplus && defined __GNUC_STDC_INLINE__ \
77 && ! defined __clang__) \
78 : ((! defined _DONT_USE_CTYPE_INLINE_ \
79 && (defined __GNUC__ || defined __cplusplus)) \
80 || (defined _FORTIFY_SOURCE && 0 < _FORTIFY_SOURCE \
81 && defined __GNUC__ && ! defined __cplusplus))))
82 # define _GL_EXTERN_INLINE_STDHEADER_BUG
83 #endif
84 #if ((__GNUC__ \
85 ? (defined __GNUC_STDC_INLINE__ && __GNUC_STDC_INLINE__ \
86 && !defined __PCC__) \
87 : (199901L <= __STDC_VERSION__ \
88 && !defined __HP_cc \
89 && !defined __PGI \
90 && !(defined __SUNPRO_C && __STDC__))) \
91 && !defined _GL_EXTERN_INLINE_STDHEADER_BUG)
92 # define _GL_INLINE inline
93 # define _GL_EXTERN_INLINE extern inline
94 # define _GL_EXTERN_INLINE_IN_USE
95 #elif (2 < __GNUC__ + (7 <= __GNUC_MINOR__) && !defined __STRICT_ANSI__ \
96 && !defined __PCC__ \
97 && !defined _GL_EXTERN_INLINE_STDHEADER_BUG)
98 # if defined __GNUC_GNU_INLINE__ && __GNUC_GNU_INLINE__
99 /* __gnu_inline__ suppresses a GCC 4.2 diagnostic. */
100 # define _GL_INLINE extern inline __attribute__ ((__gnu_inline__))
101 # else
102 # define _GL_INLINE extern inline
103 # endif
104 # define _GL_EXTERN_INLINE extern
105 # define _GL_EXTERN_INLINE_IN_USE
106 #else
107 # define _GL_INLINE _GL_UNUSED static
108 # define _GL_EXTERN_INLINE _GL_UNUSED static
109 #endif
110
111 /* In GCC 4.6 (inclusive) to 5.1 (exclusive),
112 suppress bogus "no previous prototype for 'FOO'"
113 and "no previous declaration for 'FOO'" diagnostics,
114 when FOO is an inline function in the header; see
115 <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=54113> and
116 <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63877>. */
117 #if __GNUC__ == 4 && 6 <= __GNUC_MINOR__
118 # if defined __GNUC_STDC_INLINE__ && __GNUC_STDC_INLINE__
119 # define _GL_INLINE_HEADER_CONST_PRAGMA
120 # else
121 # define _GL_INLINE_HEADER_CONST_PRAGMA \
122 _Pragma ("GCC diagnostic ignored \"-Wsuggest-attribute=const\"")
123 # endif
124 # define _GL_INLINE_HEADER_BEGIN \
125 _Pragma ("GCC diagnostic push") \
126 _Pragma ("GCC diagnostic ignored \"-Wmissing-prototypes\"") \
127 _Pragma ("GCC diagnostic ignored \"-Wmissing-declarations\"") \
128 _GL_INLINE_HEADER_CONST_PRAGMA
129 # define _GL_INLINE_HEADER_END \
130 _Pragma ("GCC diagnostic pop")
131 #else
132 # define _GL_INLINE_HEADER_BEGIN
133 # define _GL_INLINE_HEADER_END
134 #endif])
135 ])