xref: /freebsd/contrib/ntp/sntp/libopts/m4/stdnoreturn.m4 (revision a466cc55373fc3cf86837f09da729535b57e69a1)
1# Check for stdnoreturn.h that conforms to C11.
2
3dnl Copyright 2012-2018 Free Software Foundation, Inc.
4dnl This file is free software; the Free Software Foundation
5dnl gives unlimited permission to copy and/or distribute it,
6dnl with or without modifications, as long as this notice is preserved.
7
8# Prepare for substituting <stdnoreturn.h> if it is not supported.
9
10AC_DEFUN([gl_STDNORETURN_H],
11[
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                /* Do not check for 'noreturn' after the return type.
28                   C11 allows it, but it's rarely done that way
29                   and circa-2012 bleeding-edge GCC rejects it when given
30                   -Werror=old-style-declaration.  */
31                noreturn void foo1 (void) { exit (0); }
32                _Noreturn void foo2 (void) { exit (0); }
33                int testit (int argc, char **argv)
34                {
35                  if (argc & 1)
36                    return 0;
37                  (argv[0][0] ? foo1 : foo2) ();
38                }
39              ]])],
40           [gl_cv_header_working_stdnoreturn_h=yes],
41           [gl_cv_header_working_stdnoreturn_h=no])])
42      if test $gl_cv_header_working_stdnoreturn_h = yes; then
43        STDNORETURN_H=''
44      else
45        STDNORETURN_H='stdnoreturn.h'
46      fi
47      ;;
48  esac
49  AC_SUBST([STDNORETURN_H])
50  AM_CONDITIONAL([GL_GENERATE_STDNORETURN_H], [test -n "$STDNORETURN_H"])
51])
52