stdnoreturn.m4 revision 285612
1139823Simp# Check for stdnoreturn.h that conforms to C11.
210937Swollman
31541Srgrimesdnl Copyright 2012-2015 Free Software Foundation, Inc.
41541Srgrimesdnl This file is free software; the Free Software Foundation
51541Srgrimesdnl gives unlimited permission to copy and/or distribute it,
61541Srgrimesdnl with or without modifications, as long as this notice is preserved.
71541Srgrimes
81541Srgrimes# Prepare for substituting <stdnoreturn.h> if it is not supported.
91541Srgrimes
101541SrgrimesAC_DEFUN([gl_STDNORETURN_H],
111541Srgrimes[
121541Srgrimes  AC_CACHE_CHECK([for working stdnoreturn.h],
131541Srgrimes    [gl_cv_header_working_stdnoreturn_h],
141541Srgrimes    [AC_COMPILE_IFELSE(
151541Srgrimes       [AC_LANG_PROGRAM(
161541Srgrimes          [[#include <stdlib.h>
171541Srgrimes            #include <stdnoreturn.h>
181541Srgrimes            /* Do not check for 'noreturn' after the return type.
191541Srgrimes               C11 allows it, but it's rarely done that way
201541Srgrimes               and circa-2012 bleeding-edge GCC rejects it when given
211541Srgrimes               -Werror=old-style-declaration.  */
221541Srgrimes            noreturn void foo1 (void) { exit (0); }
231541Srgrimes            _Noreturn void foo2 (void) { exit (0); }
241541Srgrimes            int testit (int argc, char **argv) {
251541Srgrimes              if (argc & 1)
261541Srgrimes                return 0;
271541Srgrimes              (argv[0][0] ? foo1 : foo2) ();
281541Srgrimes            }
2910937Swollman          ]])],
3050477Speter       [gl_cv_header_working_stdnoreturn_h=yes],
311541Srgrimes       [gl_cv_header_working_stdnoreturn_h=no])])
321541Srgrimes
332169Spaul  if test $gl_cv_header_working_stdnoreturn_h = yes; then
342169Spaul    STDNORETURN_H=''
3586764Sjlemon  else
3698102Shsu    STDNORETURN_H='stdnoreturn.h'
3786764Sjlemon  fi
38195699Srwatson
39195699Srwatson  AC_SUBST([STDNORETURN_H])
40191688Szec  AM_CONDITIONAL([GL_GENERATE_STDNORETURN_H], [test -n "$STDNORETURN_H"])
411541Srgrimes])
421541Srgrimes