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