extern-inline: no 'static inline'
[gnulib.git] / m4 / extern-inline.m4
1 dnl 'extern inline' a la ISO C99.
2
3 dnl Copyright 2012 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 [/* _GL_INLINE is a portable alternative to ISO C99 plain 'inline'.
12    _GL_EXTERN_INLINE is a portable alternative to 'extern inline'.
13    _GL_INLINE_HEADER_BEGIN contains useful stuff to put
14      in an include file, before uses of _GL_INLINE.
15      It suppresses GCC's bogus "no previous prototype for 'FOO'" diagnostic,
16      when FOO is an inline function in the header; see
17      <http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54113>.
18    _GL_INLINE_HEADER_END contains useful stuff to put
19      in the same include file, after uses of _GL_INLINE.  */
20 #if (__GNUC__ \
21      ? defined __GNUC_STDC_INLINE__ && __GNUC_STDC_INLINE__ \
22      : 199901L <= __STDC_VERSION__)
23 # define _GL_INLINE inline
24 # define _GL_EXTERN_INLINE extern inline
25 #elif 2 < __GNUC__ + (7 <= __GNUC_MINOR__)
26 # if __GNUC_GNU_INLINE__
27    /* __gnu_inline__ suppresses a GCC 4.2 diagnostic.  */
28 #  define _GL_INLINE extern inline __attribute__ ((__gnu_inline__))
29 # else
30 #  define _GL_INLINE extern inline
31 # endif
32 # define _GL_EXTERN_INLINE extern
33 #else
34 # define _GL_INLINE static
35 # define _GL_EXTERN_INLINE static
36 #endif
37
38 #if 4 < __GNUC__ + (6 <= __GNUC_MINOR__)
39 # if defined __GNUC_STDC_INLINE__ && __GNUC_STDC_INLINE__
40 #  define _GL_INLINE_HEADER_CONST_PRAGMA
41 # else
42 #  define _GL_INLINE_HEADER_CONST_PRAGMA \
43      _Pragma ("GCC diagnostic ignored \"-Wsuggest-attribute=const\"")
44 # endif
45 # define _GL_INLINE_HEADER_BEGIN \
46     _Pragma ("GCC diagnostic push") \
47     _Pragma ("GCC diagnostic ignored \"-Wmissing-prototypes\"") \
48     _Pragma ("GCC diagnostic ignored \"-Wmissing-declarations\"") \
49     _GL_INLINE_HEADER_CONST_PRAGMA
50 # define _GL_INLINE_HEADER_END \
51     _Pragma ("GCC diagnostic pop")
52 #else
53 # define _GL_INLINE_HEADER_BEGIN
54 # define _GL_INLINE_HEADER_END
55 #endif])
56 ])