|
dnl 'extern inline' a la ISO C99. |
|
|
|
dnl Copyright 2012-2023 Free Software Foundation, Inc. |
|
dnl This file is free software; the Free Software Foundation |
|
dnl gives unlimited permission to copy and/or distribute it, |
|
dnl with or without modifications, as long as this notice is preserved. |
|
|
|
AC_DEFUN([gl_EXTERN_INLINE], |
|
[ |
|
AC_CACHE_CHECK([whether ctype.h defines __header_inline], |
|
[gl_cv_have___header_inline], |
|
[AC_PREPROC_IFELSE( |
|
[AC_LANG_SOURCE([[#include <ctype.h> |
|
#ifndef __header_inline |
|
#error "<ctype.h> does not define __header_inline" |
|
#endif |
|
]])], |
|
[gl_cv_have___header_inline=yes], |
|
[gl_cv_have___header_inline=no])]) |
|
if test "$gl_cv_have___header_inline" = yes; then |
|
AC_DEFINE([HAVE___HEADER_INLINE], [1], |
|
[Define to 1 if ctype.h defines __header_inline.]) |
|
fi |
|
|
|
AH_VERBATIM([HAVE___HEADER_INLINE_1], |
|
[/* Please see the Gnulib manual for how to use these macros. |
|
|
|
Suppress extern inline with HP-UX cc, as it appears to be broken; see |
|
<https: |
|
|
|
Suppress extern inline with Sun C in standards-conformance mode, as it |
|
mishandles inline functions that call each other. E.g., for 'inline void f |
|
(void) { } inline void g (void) { f (); }', c99 incorrectly complains |
|
'reference to static identifier "f" in extern inline function'. |
|
This bug was observed with Oracle Developer Studio 12.6 |
|
(Sun C 5.15 SunOS_sparc 2017/05/30). |
|
|
|
Suppress extern inline (with or without __attribute__ ((__gnu_inline__))) |
|
on configurations that mistakenly use 'static inline' to implement |
|
functions or macros in standard C headers like <ctype.h>. For example, |
|
if isdigit is mistakenly implemented via a static inline function, |
|
a program containing an extern inline function that calls isdigit |
|
may not work since the C standard prohibits extern inline functions |
|
from calling static functions (ISO C 99 section 6.7.4.(3). |
|
This bug is known to occur on: |
|
|
|
OS X 10.8 and earlier; see: |
|
https: |
|
|
|
DragonFly; see |
|
http: |
|
|
|
FreeBSD; see: |
|
https: |
|
|
|
OS X 10.9 has a macro __header_inline indicating the bug is fixed for C and |
|
for clang but remains for g++; see <https: |
|
Assume DragonFly and FreeBSD will be similar. |
|
|
|
GCC 4.3 and above with -std=c99 or -std=gnu99 implements ISO C99 |
|
inline semantics, unless -fgnu89-inline is used. It defines a macro |
|
__GNUC_STDC_INLINE__ to indicate this situation or a macro |
|
__GNUC_GNU_INLINE__ to indicate the opposite situation. |
|
GCC 4.2 with -std=c99 or -std=gnu99 implements the GNU C inline |
|
semantics but warns, unless -fgnu89-inline is used: |
|
warning: C99 inline functions are not supported; using GNU89 |
|
warning: to disable this warning use -fgnu89-inline or the gnu_inline function attribute |
|
It defines a macro __GNUC_GNU_INLINE__ to indicate this situation. |
|
*/ |
|
#if (((defined __APPLE__ && defined __MACH__) \ |
|
|| defined __DragonFly__ || defined __FreeBSD__) \ |
|
&& (defined HAVE___HEADER_INLINE \ |
|
? (defined __cplusplus && defined __GNUC_STDC_INLINE__ \ |
|
&& ! defined __clang__) \ |
|
: ((! defined _DONT_USE_CTYPE_INLINE_ \ |
|
&& (defined __GNUC__ || defined __cplusplus)) \ |
|
|| (defined _FORTIFY_SOURCE && 0 < _FORTIFY_SOURCE \ |
|
&& defined __GNUC__ && ! defined __cplusplus)))) |
|
# define _GL_EXTERN_INLINE_STDHEADER_BUG |
|
#endif |
|
#if ((__GNUC__ \ |
|
? defined __GNUC_STDC_INLINE__ && __GNUC_STDC_INLINE__ \ |
|
: (199901L <= __STDC_VERSION__ \ |
|
&& !defined __HP_cc \ |
|
&& !defined __PGI \ |
|
&& !(defined __SUNPRO_C && __STDC__))) \ |
|
&& !defined _GL_EXTERN_INLINE_STDHEADER_BUG) |
|
# define _GL_INLINE inline |
|
# define _GL_EXTERN_INLINE extern inline |
|
# define _GL_EXTERN_INLINE_IN_USE |
|
#elif (2 < __GNUC__ + (7 <= __GNUC_MINOR__) && !defined __STRICT_ANSI__ \ |
|
&& !defined _GL_EXTERN_INLINE_STDHEADER_BUG) |
|
# if defined __GNUC_GNU_INLINE__ && __GNUC_GNU_INLINE__ |
|
/* __gnu_inline__ suppresses a GCC 4.2 diagnostic. */ |
|
# define _GL_INLINE extern inline __attribute__ ((__gnu_inline__)) |
|
# else |
|
# define _GL_INLINE extern inline |
|
# endif |
|
# define _GL_EXTERN_INLINE extern |
|
# define _GL_EXTERN_INLINE_IN_USE |
|
#else |
|
# define _GL_INLINE _GL_UNUSED static |
|
# define _GL_EXTERN_INLINE _GL_UNUSED static |
|
#endif |
|
|
|
/* In GCC 4.6 (inclusive) to 5.1 (exclusive), |
|
suppress bogus "no previous prototype for 'FOO'" |
|
and "no previous declaration for 'FOO'" diagnostics, |
|
when FOO is an inline function in the header; see |
|
<https: |
|
<https: |
|
#if __GNUC__ == 4 && 6 <= __GNUC_MINOR__ |
|
# if defined __GNUC_STDC_INLINE__ && __GNUC_STDC_INLINE__ |
|
# define _GL_INLINE_HEADER_CONST_PRAGMA |
|
# else |
|
# define _GL_INLINE_HEADER_CONST_PRAGMA \ |
|
_Pragma ("GCC diagnostic ignored \"-Wsuggest-attribute=const\"") |
|
# endif |
|
# define _GL_INLINE_HEADER_BEGIN \ |
|
_Pragma ("GCC diagnostic push") \ |
|
_Pragma ("GCC diagnostic ignored \"-Wmissing-prototypes\"") \ |
|
_Pragma ("GCC diagnostic ignored \"-Wmissing-declarations\"") \ |
|
_GL_INLINE_HEADER_CONST_PRAGMA |
|
# define _GL_INLINE_HEADER_END \ |
|
_Pragma ("GCC diagnostic pop") |
|
#else |
|
# define _GL_INLINE_HEADER_BEGIN |
|
# define _GL_INLINE_HEADER_END |
|
#endif]) |
|
]) |
|
|