1*1424dfb3Schristosdnl 'extern inline' a la ISO C99. 2*1424dfb3Schristos 3*1424dfb3Schristosdnl Copyright 2012-2020 Free Software Foundation, Inc. 4*1424dfb3Schristosdnl This file is free software; the Free Software Foundation 5*1424dfb3Schristosdnl gives unlimited permission to copy and/or distribute it, 6*1424dfb3Schristosdnl with or without modifications, as long as this notice is preserved. 7*1424dfb3Schristos 8*1424dfb3SchristosAC_DEFUN([gl_EXTERN_INLINE], 9*1424dfb3Schristos[ 10*1424dfb3Schristos AH_VERBATIM([extern_inline], 11*1424dfb3Schristos[/* Please see the Gnulib manual for how to use these macros. 12*1424dfb3Schristos 13*1424dfb3Schristos Suppress extern inline with HP-UX cc, as it appears to be broken; see 14*1424dfb3Schristos <https://lists.gnu.org/r/bug-texinfo/2013-02/msg00030.html>. 15*1424dfb3Schristos 16*1424dfb3Schristos Suppress extern inline with Sun C in standards-conformance mode, as it 17*1424dfb3Schristos mishandles inline functions that call each other. E.g., for 'inline void f 18*1424dfb3Schristos (void) { } inline void g (void) { f (); }', c99 incorrectly complains 19*1424dfb3Schristos 'reference to static identifier "f" in extern inline function'. 20*1424dfb3Schristos This bug was observed with Sun C 5.12 SunOS_i386 2011/11/16. 21*1424dfb3Schristos 22*1424dfb3Schristos Suppress extern inline (with or without __attribute__ ((__gnu_inline__))) 23*1424dfb3Schristos on configurations that mistakenly use 'static inline' to implement 24*1424dfb3Schristos functions or macros in standard C headers like <ctype.h>. For example, 25*1424dfb3Schristos if isdigit is mistakenly implemented via a static inline function, 26*1424dfb3Schristos a program containing an extern inline function that calls isdigit 27*1424dfb3Schristos may not work since the C standard prohibits extern inline functions 28*1424dfb3Schristos from calling static functions (ISO C 99 section 6.7.4.(3). 29*1424dfb3Schristos This bug is known to occur on: 30*1424dfb3Schristos 31*1424dfb3Schristos OS X 10.8 and earlier; see: 32*1424dfb3Schristos https://lists.gnu.org/r/bug-gnulib/2012-12/msg00023.html 33*1424dfb3Schristos 34*1424dfb3Schristos DragonFly; see 35*1424dfb3Schristos http://muscles.dragonflybsd.org/bulk/clang-master-potential/20141111_102002/logs/ah-tty-0.3.12.log 36*1424dfb3Schristos 37*1424dfb3Schristos FreeBSD; see: 38*1424dfb3Schristos https://lists.gnu.org/r/bug-gnulib/2014-07/msg00104.html 39*1424dfb3Schristos 40*1424dfb3Schristos OS X 10.9 has a macro __header_inline indicating the bug is fixed for C and 41*1424dfb3Schristos for clang but remains for g++; see <https://trac.macports.org/ticket/41033>. 42*1424dfb3Schristos Assume DragonFly and FreeBSD will be similar. 43*1424dfb3Schristos 44*1424dfb3Schristos GCC 4.3 and above with -std=c99 or -std=gnu99 implements ISO C99 45*1424dfb3Schristos inline semantics, unless -fgnu89-inline is used. It defines a macro 46*1424dfb3Schristos __GNUC_STDC_INLINE__ to indicate this situation or a macro 47*1424dfb3Schristos __GNUC_GNU_INLINE__ to indicate the opposite situation. 48*1424dfb3Schristos GCC 4.2 with -std=c99 or -std=gnu99 implements the GNU C inline 49*1424dfb3Schristos semantics but warns, unless -fgnu89-inline is used: 50*1424dfb3Schristos warning: C99 inline functions are not supported; using GNU89 51*1424dfb3Schristos warning: to disable this warning use -fgnu89-inline or the gnu_inline function attribute 52*1424dfb3Schristos It defines a macro __GNUC_GNU_INLINE__ to indicate this situation. 53*1424dfb3Schristos */ 54*1424dfb3Schristos#if (((defined __APPLE__ && defined __MACH__) \ 55*1424dfb3Schristos || defined __DragonFly__ || defined __FreeBSD__) \ 56*1424dfb3Schristos && (defined __header_inline \ 57*1424dfb3Schristos ? (defined __cplusplus && defined __GNUC_STDC_INLINE__ \ 58*1424dfb3Schristos && ! defined __clang__) \ 59*1424dfb3Schristos : ((! defined _DONT_USE_CTYPE_INLINE_ \ 60*1424dfb3Schristos && (defined __GNUC__ || defined __cplusplus)) \ 61*1424dfb3Schristos || (defined _FORTIFY_SOURCE && 0 < _FORTIFY_SOURCE \ 62*1424dfb3Schristos && defined __GNUC__ && ! defined __cplusplus)))) 63*1424dfb3Schristos# define _GL_EXTERN_INLINE_STDHEADER_BUG 64*1424dfb3Schristos#endif 65*1424dfb3Schristos#if ((__GNUC__ \ 66*1424dfb3Schristos ? defined __GNUC_STDC_INLINE__ && __GNUC_STDC_INLINE__ \ 67*1424dfb3Schristos : (199901L <= __STDC_VERSION__ \ 68*1424dfb3Schristos && !defined __HP_cc \ 69*1424dfb3Schristos && !defined __PGI \ 70*1424dfb3Schristos && !(defined __SUNPRO_C && __STDC__))) \ 71*1424dfb3Schristos && !defined _GL_EXTERN_INLINE_STDHEADER_BUG) 72*1424dfb3Schristos# define _GL_INLINE inline 73*1424dfb3Schristos# define _GL_EXTERN_INLINE extern inline 74*1424dfb3Schristos# define _GL_EXTERN_INLINE_IN_USE 75*1424dfb3Schristos#elif (2 < __GNUC__ + (7 <= __GNUC_MINOR__) && !defined __STRICT_ANSI__ \ 76*1424dfb3Schristos && !defined _GL_EXTERN_INLINE_STDHEADER_BUG) 77*1424dfb3Schristos# if defined __GNUC_GNU_INLINE__ && __GNUC_GNU_INLINE__ 78*1424dfb3Schristos /* __gnu_inline__ suppresses a GCC 4.2 diagnostic. */ 79*1424dfb3Schristos# define _GL_INLINE extern inline __attribute__ ((__gnu_inline__)) 80*1424dfb3Schristos# else 81*1424dfb3Schristos# define _GL_INLINE extern inline 82*1424dfb3Schristos# endif 83*1424dfb3Schristos# define _GL_EXTERN_INLINE extern 84*1424dfb3Schristos# define _GL_EXTERN_INLINE_IN_USE 85*1424dfb3Schristos#else 86*1424dfb3Schristos# define _GL_INLINE static _GL_UNUSED 87*1424dfb3Schristos# define _GL_EXTERN_INLINE static _GL_UNUSED 88*1424dfb3Schristos#endif 89*1424dfb3Schristos 90*1424dfb3Schristos/* In GCC 4.6 (inclusive) to 5.1 (exclusive), 91*1424dfb3Schristos suppress bogus "no previous prototype for 'FOO'" 92*1424dfb3Schristos and "no previous declaration for 'FOO'" diagnostics, 93*1424dfb3Schristos when FOO is an inline function in the header; see 94*1424dfb3Schristos <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=54113> and 95*1424dfb3Schristos <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63877>. */ 96*1424dfb3Schristos#if __GNUC__ == 4 && 6 <= __GNUC_MINOR__ 97*1424dfb3Schristos# if defined __GNUC_STDC_INLINE__ && __GNUC_STDC_INLINE__ 98*1424dfb3Schristos# define _GL_INLINE_HEADER_CONST_PRAGMA 99*1424dfb3Schristos# else 100*1424dfb3Schristos# define _GL_INLINE_HEADER_CONST_PRAGMA \ 101*1424dfb3Schristos _Pragma ("GCC diagnostic ignored \"-Wsuggest-attribute=const\"") 102*1424dfb3Schristos# endif 103*1424dfb3Schristos# define _GL_INLINE_HEADER_BEGIN \ 104*1424dfb3Schristos _Pragma ("GCC diagnostic push") \ 105*1424dfb3Schristos _Pragma ("GCC diagnostic ignored \"-Wmissing-prototypes\"") \ 106*1424dfb3Schristos _Pragma ("GCC diagnostic ignored \"-Wmissing-declarations\"") \ 107*1424dfb3Schristos _GL_INLINE_HEADER_CONST_PRAGMA 108*1424dfb3Schristos# define _GL_INLINE_HEADER_END \ 109*1424dfb3Schristos _Pragma ("GCC diagnostic pop") 110*1424dfb3Schristos#else 111*1424dfb3Schristos# define _GL_INLINE_HEADER_BEGIN 112*1424dfb3Schristos# define _GL_INLINE_HEADER_END 113*1424dfb3Schristos#endif]) 114*1424dfb3Schristos]) 115