c-bool.m4 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. # Check for bool that conforms to C2023.
  2. dnl Copyright 2022-2023 Free Software Foundation, Inc.
  3. dnl This file is free software; the Free Software Foundation
  4. dnl gives unlimited permission to copy and/or distribute it,
  5. dnl with or without modifications, as long as this notice is preserved.
  6. AC_DEFUN([gl_C_BOOL],
  7. [
  8. AC_CACHE_CHECK([for bool, true, false], [gl_cv_c_bool],
  9. [AC_COMPILE_IFELSE(
  10. [AC_LANG_SOURCE([[
  11. #if true == false
  12. #error "true == false"
  13. #endif
  14. extern bool b;
  15. bool b = true == false;]])],
  16. [gl_cv_c_bool=yes],
  17. [gl_cv_c_bool=no])])
  18. if test "$gl_cv_c_bool" = yes; then
  19. AC_DEFINE([HAVE_C_BOOL], [1],
  20. [Define to 1 if bool, true and false work as per C2023.])
  21. fi
  22. AC_CHECK_HEADERS_ONCE([stdbool.h])
  23. dnl The "zz" puts this toward config.h's end, to avoid potential
  24. dnl collisions with other definitions.
  25. dnl If 'bool', 'true' and 'false' do not work, arrange for them to work.
  26. dnl In C, this means including <stdbool.h> if it is not already included.
  27. dnl However, if the preprocessor mistakenly treats 'true' as 0,
  28. dnl define it to a bool expression equal to 1; this is needed in
  29. dnl Sun C++ 5.11 (Oracle Solaris Studio 12.2, 2010) and older.
  30. AH_VERBATIM([zzbool],
  31. [#ifndef HAVE_C_BOOL
  32. # if !defined __cplusplus && !defined __bool_true_false_are_defined
  33. # if HAVE_STDBOOL_H
  34. # include <stdbool.h>
  35. # else
  36. # if defined __SUNPRO_C
  37. # error "<stdbool.h> is not usable with this configuration. To make it usable, add -D_STDC_C99= to $CC."
  38. # else
  39. # error "<stdbool.h> does not exist on this platform. Use gnulib module 'stdbool-c99' instead of gnulib module 'stdbool'."
  40. # endif
  41. # endif
  42. # endif
  43. # if !true
  44. # define true (!false)
  45. # endif
  46. #endif])
  47. ])