immutable: Add tests.
[gnulib.git] / m4 / stdnoreturn.m4
blob207aa249b4cbd4727febfdaaa186a262a42a94f3
1 # Check for stdnoreturn.h that conforms to C11.
3 dnl Copyright 2012-2021 Free Software Foundation, Inc.
4 dnl This file is free software; the Free Software Foundation
5 dnl gives unlimited permission to copy and/or distribute it,
6 dnl with or without modifications, as long as this notice is preserved.
8 # Prepare for substituting <stdnoreturn.h> if it is not supported.
10 AC_DEFUN([gl_STDNORETURN_H],
12   AC_REQUIRE([AC_CANONICAL_HOST])
13   case "$host_os" in
14     cygwin*)
15       dnl Regardless whether a working <stdnoreturn.h> exists or not,
16       dnl we need our own <stdnoreturn.h>, because of the definition
17       dnl of _Noreturn done by gnulib-common.m4.
18       STDNORETURN_H='stdnoreturn.h'
19       ;;
20     *)
21       AC_CACHE_CHECK([for working stdnoreturn.h],
22         [gl_cv_header_working_stdnoreturn_h],
23         [AC_COMPILE_IFELSE(
24            [AC_LANG_PROGRAM(
25               [[#include <stdlib.h>
26                 #include <stdnoreturn.h>
27                 #if defined _WIN32 && !defined __CYGWIN__
28                 # include <process.h>
29                 #endif
30                 /* Do not check for 'noreturn' after the return type.
31                    C11 allows it, but it's rarely done that way
32                    and circa-2012 bleeding-edge GCC rejects it when given
33                    -Werror=old-style-declaration.  */
34                 noreturn void foo1 (void) { exit (0); }
35                 _Noreturn void foo2 (void) { exit (0); }
36                 int testit (int argc, char **argv)
37                 {
38                   if (argc & 1)
39                     return 0;
40                   (argv[0][0] ? foo1 : foo2) ();
41                 }
42               ]])],
43            [gl_cv_header_working_stdnoreturn_h=yes],
44            [gl_cv_header_working_stdnoreturn_h=no])])
45       if test $gl_cv_header_working_stdnoreturn_h = yes; then
46         STDNORETURN_H=''
47       else
48         STDNORETURN_H='stdnoreturn.h'
49       fi
50       ;;
51   esac
52   AC_SUBST([STDNORETURN_H])
53   AM_CONDITIONAL([GL_GENERATE_STDNORETURN_H], [test -n "$STDNORETURN_H"])