stdnoreturn: new module
[gnulib.git] / m4 / stdnoreturn.m4
1 # Check for stdnoreturn.h that conforms to C11.
2
3 dnl Copyright 2012 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.
7
8 # Prepare for substituting <stdnoreturn.h> if it is not supported.
9
10 AC_DEFUN([gl_STDNORETURN_H],
11 [
12   AC_CACHE_CHECK([for working stdnoreturn.h],
13     [gl_cv_header_working_stdnoreturn_h],
14     [AC_COMPILE_IFELSE(
15        [AC_LANG_PROGRAM(
16           [[#include <stdlib.h>
17             #include <stdnoreturn.h>
18             void noreturn foo1 (void) { exit (0); }
19             void _Noreturn foo2 (void) { exit (0); }
20             noreturn void foo3 (void) { exit (0); }
21             _Noreturn void foo4 (void) { exit (0); }
22             int main (int argc, char **argv) {
23               if (argc & 1)
24                 return 0;
25               ((argv[0][0]
26                 ? (argv[0][1] ? foo1 : foo2)
27                 : (argv[0][1] ? foo3 : foo4))
28                ());
29             }
30           ]])],
31        [gl_cv_header_working_stdnoreturn_h=yes],
32        [gl_cv_header_working_stdnoreturn_h=no])])
33
34   if test $gl_cv_header_working_stdnoreturn_h = yes; then
35     STDNORETURN_H=''
36   else
37     STDNORETURN_H='stdnoreturn.h'
38   fi
39
40   AC_SUBST([STDNORETURN_H])
41   AM_CONDITIONAL([GL_GENERATE_STDNORETURN_H], [test -n "$STDNORETURN_H"])
42 ])