stdnoreturn.m4 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. # Check for stdnoreturn.h that conforms to C11.
  2. dnl Copyright 2012-2018 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. # Prepare for substituting <stdnoreturn.h> if it is not supported.
  7. AC_DEFUN([gl_STDNORETURN_H],
  8. [
  9. AC_REQUIRE([AC_CANONICAL_HOST])
  10. case "$host_os" in
  11. cygwin*)
  12. dnl Regardless whether a working <stdnoreturn.h> exists or not,
  13. dnl we need our own <stdnoreturn.h>, because of the definition
  14. dnl of _Noreturn done by gnulib-common.m4.
  15. STDNORETURN_H='stdnoreturn.h'
  16. ;;
  17. *)
  18. AC_CACHE_CHECK([for working stdnoreturn.h],
  19. [gl_cv_header_working_stdnoreturn_h],
  20. [AC_COMPILE_IFELSE(
  21. [AC_LANG_PROGRAM(
  22. [[#include <stdlib.h>
  23. #include <stdnoreturn.h>
  24. /* Do not check for 'noreturn' after the return type.
  25. C11 allows it, but it's rarely done that way
  26. and circa-2012 bleeding-edge GCC rejects it when given
  27. -Werror=old-style-declaration. */
  28. noreturn void foo1 (void) { exit (0); }
  29. _Noreturn void foo2 (void) { exit (0); }
  30. int testit (int argc, char **argv)
  31. {
  32. if (argc & 1)
  33. return 0;
  34. (argv[0][0] ? foo1 : foo2) ();
  35. }
  36. ]])],
  37. [gl_cv_header_working_stdnoreturn_h=yes],
  38. [gl_cv_header_working_stdnoreturn_h=no])])
  39. if test $gl_cv_header_working_stdnoreturn_h = yes; then
  40. STDNORETURN_H=''
  41. else
  42. STDNORETURN_H='stdnoreturn.h'
  43. fi
  44. ;;
  45. esac
  46. AC_SUBST([STDNORETURN_H])
  47. AM_CONDITIONAL([GL_GENERATE_STDNORETURN_H], [test -n "$STDNORETURN_H"])
  48. ])