4862d60d8e7416d109c9e5428225015ffefeac4d
[gnulib.git] / m4 / extern-inline.m4
1 dnl 'extern inline' a la ISO C99.
2
3 dnl Copyright 2012-2013 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
8 AC_DEFUN([gl_EXTERN_INLINE],
9 [
10   AH_VERBATIM([extern_inline],
11 [/* Please see the Gnulib manual for how to use these macros.
12
13    Suppress extern inline with HP-UX cc, as it appears to be broken; see
14    <http://lists.gnu.org/archive/html/bug-texinfo/2013-02/msg00030.html>.
15
16    Suppress extern inline with Sun C in standards-conformance mode, as it
17    mishandles inline functions that call each other.  E.g., for 'inline void f
18    (void) { } inline void g (void) { f (); }', c99 incorrectly complains
19    'reference to static identifier "f" in extern inline function'.
20    This bug was observed with Sun C 5.12 SunOS_i386 2011/11/16.
21
22    Suppress the use of extern inline on problematic Apple configurations, as
23    Libc at least through Libc-825.26 (2013-04-09) mishandles it; see, e.g.,
24    <http://lists.gnu.org/archive/html/bug-gnulib/2012-12/msg00023.html>.
25    Perhaps Apple will fix this some day.  */
26 #if (defined __APPLE__ \
27      && ((! defined _DONT_USE_CTYPE_INLINE_ \
28           && (defined __GNUC__ || defined __cplusplus)) \
29          || (defined _FORTIFY_SOURCE && 0 < _FORTIFY_SOURCE \
30              && defined __GNUC__ && ! defined __cplusplus)))
31 # define _GL_EXTERN_INLINE_APPLE_BUG
32 #endif
33 #if ((__GNUC__ \
34       ? defined __GNUC_STDC_INLINE__ && __GNUC_STDC_INLINE__ \
35       : (199901L <= __STDC_VERSION__ \
36          && !defined __HP_cc \
37          && !(defined __SUNPRO_C && __STDC__))) \
38      && !defined _GL_EXTERN_INLINE_APPLE_BUG)
39 # define _GL_INLINE inline
40 # define _GL_EXTERN_INLINE extern inline
41 # define _GL_EXTERN_INLINE_IN_USE
42 #elif (2 < __GNUC__ + (7 <= __GNUC_MINOR__) && !defined __STRICT_ANSI__ \
43        && !defined _GL_EXTERN_INLINE_APPLE_BUG)
44 # if __GNUC_GNU_INLINE__
45    /* __gnu_inline__ suppresses a GCC 4.2 diagnostic.  */
46 #  define _GL_INLINE extern inline __attribute__ ((__gnu_inline__))
47 # else
48 #  define _GL_INLINE extern inline
49 # endif
50 # define _GL_EXTERN_INLINE extern
51 # define _GL_EXTERN_INLINE_IN_USE
52 #else
53 # define _GL_INLINE static _GL_UNUSED
54 # define _GL_EXTERN_INLINE static _GL_UNUSED
55 #endif
56
57 #if 4 < __GNUC__ + (6 <= __GNUC_MINOR__)
58 # if defined __GNUC_STDC_INLINE__ && __GNUC_STDC_INLINE__
59 #  define _GL_INLINE_HEADER_CONST_PRAGMA
60 # else
61 #  define _GL_INLINE_HEADER_CONST_PRAGMA \
62      _Pragma ("GCC diagnostic ignored \"-Wsuggest-attribute=const\"")
63 # endif
64   /* Suppress GCC's bogus "no previous prototype for 'FOO'"
65      and "no previous declaration for 'FOO'"  diagnostics,
66      when FOO is an inline function in the header; see
67      <http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54113>.  */
68 # define _GL_INLINE_HEADER_BEGIN \
69     _Pragma ("GCC diagnostic push") \
70     _Pragma ("GCC diagnostic ignored \"-Wmissing-prototypes\"") \
71     _Pragma ("GCC diagnostic ignored \"-Wmissing-declarations\"") \
72     _GL_INLINE_HEADER_CONST_PRAGMA
73 # define _GL_INLINE_HEADER_END \
74     _Pragma ("GCC diagnostic pop")
75 #else
76 # define _GL_INLINE_HEADER_BEGIN
77 # define _GL_INLINE_HEADER_END
78 #endif])
79 ])