Blame m4/stdbool.m4

Packit Service 4684c1
# Check for stdbool.h that conforms to C99.
Packit Service 4684c1
Packit Service 4684c1
dnl Copyright (C) 2002-2006, 2009-2020 Free Software Foundation, Inc.
Packit Service 4684c1
dnl This file is free software; the Free Software Foundation
Packit Service 4684c1
dnl gives unlimited permission to copy and/or distribute it,
Packit Service 4684c1
dnl with or without modifications, as long as this notice is preserved.
Packit Service 4684c1
Packit Service 4684c1
#serial 8
Packit Service 4684c1
Packit Service 4684c1
# Prepare for substituting <stdbool.h> if it is not supported.
Packit Service 4684c1
Packit Service 4684c1
AC_DEFUN([AM_STDBOOL_H],
Packit Service 4684c1
[
Packit Service 4684c1
  AC_REQUIRE([AC_CHECK_HEADER_STDBOOL])
Packit Service 4684c1
  AC_REQUIRE([AC_CANONICAL_HOST])
Packit Service 4684c1
Packit Service 4684c1
  dnl On some platforms, <stdbool.h> does not exist or does not conform to C99.
Packit Service 4684c1
  dnl On Solaris 10 with CC=cc CXX=CC, <stdbool.h> exists but is not usable
Packit Service 4684c1
  dnl in C++ mode (and no <cstdbool> exists). In this case, we use our
Packit Service 4684c1
  dnl replacement, also in C mode (for binary compatibility between C and C++).
Packit Service 4684c1
  if test "$ac_cv_header_stdbool_h" = yes; then
Packit Service 4684c1
    case "$host_os" in
Packit Service 4684c1
      solaris*)
Packit Service 4684c1
        if test -z "$GCC"; then
Packit Service 4684c1
          STDBOOL_H='stdbool.h'
Packit Service 4684c1
        else
Packit Service 4684c1
          STDBOOL_H=''
Packit Service 4684c1
        fi
Packit Service 4684c1
        ;;
Packit Service 4684c1
      *)
Packit Service 4684c1
        STDBOOL_H=''
Packit Service 4684c1
        ;;
Packit Service 4684c1
    esac
Packit Service 4684c1
  else
Packit Service 4684c1
    STDBOOL_H='stdbool.h'
Packit Service 4684c1
  fi
Packit Service 4684c1
  AC_SUBST([STDBOOL_H])
Packit Service 4684c1
  AM_CONDITIONAL([GL_GENERATE_STDBOOL_H], [test -n "$STDBOOL_H"])
Packit Service 4684c1
Packit Service 4684c1
  if test "$ac_cv_type__Bool" = yes; then
Packit Service 4684c1
    HAVE__BOOL=1
Packit Service 4684c1
  else
Packit Service 4684c1
    HAVE__BOOL=0
Packit Service 4684c1
  fi
Packit Service 4684c1
  AC_SUBST([HAVE__BOOL])
Packit Service 4684c1
])
Packit Service 4684c1
Packit Service 4684c1
# AM_STDBOOL_H will be renamed to gl_STDBOOL_H in the future.
Packit Service 4684c1
AC_DEFUN([gl_STDBOOL_H], [AM_STDBOOL_H])
Packit Service 4684c1
Packit Service 4684c1
# This version of the macro is needed in autoconf <= 2.68.
Packit Service 4684c1
Packit Service 4684c1
AC_DEFUN([AC_CHECK_HEADER_STDBOOL],
Packit Service 4684c1
  [AC_CACHE_CHECK([for stdbool.h that conforms to C99],
Packit Service 4684c1
     [ac_cv_header_stdbool_h],
Packit Service 4684c1
     [AC_COMPILE_IFELSE(
Packit Service 4684c1
        [AC_LANG_PROGRAM(
Packit Service 4684c1
           [[
Packit Service 4684c1
             #include <stdbool.h>
Packit Service 4684c1
Packit Service 4684c1
             #ifdef __cplusplus
Packit Service 4684c1
              typedef bool Bool;
Packit Service 4684c1
             #else
Packit Service 4684c1
              typedef _Bool Bool;
Packit Service 4684c1
              #ifndef bool
Packit Service 4684c1
               "error: bool is not defined"
Packit Service 4684c1
              #endif
Packit Service 4684c1
              #ifndef false
Packit Service 4684c1
               "error: false is not defined"
Packit Service 4684c1
              #endif
Packit Service 4684c1
              #if false
Packit Service 4684c1
               "error: false is not 0"
Packit Service 4684c1
              #endif
Packit Service 4684c1
              #ifndef true
Packit Service 4684c1
               "error: true is not defined"
Packit Service 4684c1
              #endif
Packit Service 4684c1
              #if true != 1
Packit Service 4684c1
               "error: true is not 1"
Packit Service 4684c1
              #endif
Packit Service 4684c1
             #endif
Packit Service 4684c1
Packit Service 4684c1
             #ifndef __bool_true_false_are_defined
Packit Service 4684c1
              "error: __bool_true_false_are_defined is not defined"
Packit Service 4684c1
             #endif
Packit Service 4684c1
Packit Service 4684c1
             struct s { Bool s: 1; Bool t; bool u: 1; bool v; } s;
Packit Service 4684c1
Packit Service 4684c1
             char a[true == 1 ? 1 : -1];
Packit Service 4684c1
             char b[false == 0 ? 1 : -1];
Packit Service 4684c1
             char c[__bool_true_false_are_defined == 1 ? 1 : -1];
Packit Service 4684c1
             char d[(bool) 0.5 == true ? 1 : -1];
Packit Service 4684c1
             /* See body of main program for 'e'.  */
Packit Service 4684c1
             char f[(Bool) 0.0 == false ? 1 : -1];
Packit Service 4684c1
             char g[true];
Packit Service 4684c1
             char h[sizeof (Bool)];
Packit Service 4684c1
             char i[sizeof s.t];
Packit Service 4684c1
             enum { j = false, k = true, l = false * true, m = true * 256 };
Packit Service 4684c1
             /* The following fails for
Packit Service 4684c1
                HP aC++/ANSI C B3910B A.05.55 [Dec 04 2003]. */
Packit Service 4684c1
             Bool n[m];
Packit Service 4684c1
             char o[sizeof n == m * sizeof n[0] ? 1 : -1];
Packit Service 4684c1
             char p[-1 - (Bool) 0 < 0 && -1 - (bool) 0 < 0 ? 1 : -1];
Packit Service 4684c1
             /* Catch a bug in an HP-UX C compiler.  See
Packit Service 4684c1
                https://gcc.gnu.org/ml/gcc-patches/2003-12/msg02303.html
Packit Service 4684c1
                https://lists.gnu.org/r/bug-coreutils/2005-11/msg00161.html
Packit Service 4684c1
              */
Packit Service 4684c1
             Bool q = true;
Packit Service 4684c1
             Bool *pq = &q;
Packit Service 4684c1
             bool *qq = &q;
Packit Service 4684c1
           ]],
Packit Service 4684c1
           [[
Packit Service 4684c1
             bool e = &s;
Packit Service 4684c1
             *pq |= q; *pq |= ! q;
Packit Service 4684c1
             *qq |= q; *qq |= ! q;
Packit Service 4684c1
             /* Refer to every declared value, to avoid compiler optimizations.  */
Packit Service 4684c1
             return (!a + !b + !c + !d + !e + !f + !g + !h + !i + !!j + !k + !!l
Packit Service 4684c1
                     + !m + !n + !o + !p + !q + !pq + !qq);
Packit Service 4684c1
           ]])],
Packit Service 4684c1
        [ac_cv_header_stdbool_h=yes],
Packit Service 4684c1
        [ac_cv_header_stdbool_h=no])])
Packit Service 4684c1
   AC_CHECK_TYPES([_Bool])
Packit Service 4684c1
])