"Fossies" - the Fresh Open Source Software Archive

Member "CSSC-1.4.1/m4/std-gnu11.m4" (7 Feb 2016, 24311 Bytes) of package /linux/privat/CSSC-1.4.1.tar.gz:


As a special service "Fossies" has tried to format the requested text file into HTML format (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file.

    1 # Prefer GNU C11 and C++11 to earlier versions.  -*- coding: utf-8 -*-
    2 
    3 # This implementation is taken from GNU Autoconf lib/autoconf/c.m4
    4 # commit 5ad3567c3cbd90b4faa6539c35bc4a8c6500f535
    5 # dated 2015-10-08 10:12:41 2015 +0200.
    6 # This implementation will be obsolete once we can assume Autoconf 2.70
    7 # or later is installed everywhere a Gnulib program might be developed.
    8 
    9 
   10 # Copyright (C) 2001-2016 Free Software Foundation, Inc.
   11 
   12 # This program is free software; you can redistribute it and/or modify
   13 # it under the terms of the GNU General Public License as published by
   14 # the Free Software Foundation, either version 3 of the License, or
   15 # (at your option) any later version.
   16 #
   17 # This program is distributed in the hope that it will be useful,
   18 # but WITHOUT ANY WARRANTY; without even the implied warranty of
   19 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   20 # GNU General Public License for more details.
   21 #
   22 # You should have received a copy of the GNU General Public License
   23 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
   24 
   25 # Written by David MacKenzie, with help from
   26 # Akim Demaille, Paul Eggert,
   27 # Fran├žois Pinard, Karl Berry, Richard Pixley, Ian Lance Taylor,
   28 # Roland McGrath, Noah Friedman, david d zuhn, and many others.
   29 
   30 
   31 # AC_PROG_CC([COMPILER ...])
   32 # --------------------------
   33 # COMPILER ... is a space separated list of C compilers to search for.
   34 # This just gives the user an opportunity to specify an alternative
   35 # search list for the C compiler.
   36 AC_DEFUN_ONCE([AC_PROG_CC],
   37 [AC_LANG_PUSH(C)dnl
   38 AC_ARG_VAR([CC],     [C compiler command])dnl
   39 AC_ARG_VAR([CFLAGS], [C compiler flags])dnl
   40 _AC_ARG_VAR_LDFLAGS()dnl
   41 _AC_ARG_VAR_LIBS()dnl
   42 _AC_ARG_VAR_CPPFLAGS()dnl
   43 m4_ifval([$1],
   44       [AC_CHECK_TOOLS(CC, [$1])],
   45 [AC_CHECK_TOOL(CC, gcc)
   46 if test -z "$CC"; then
   47   dnl Here we want:
   48   dnl	AC_CHECK_TOOL(CC, cc)
   49   dnl but without the check for a tool without the prefix.
   50   dnl Until the check is removed from there, copy the code:
   51   if test -n "$ac_tool_prefix"; then
   52     AC_CHECK_PROG(CC, [${ac_tool_prefix}cc], [${ac_tool_prefix}cc])
   53   fi
   54 fi
   55 if test -z "$CC"; then
   56   AC_CHECK_PROG(CC, cc, cc, , , /usr/ucb/cc)
   57 fi
   58 if test -z "$CC"; then
   59   AC_CHECK_TOOLS(CC, cl.exe)
   60 fi
   61 ])
   62 
   63 test -z "$CC" && AC_MSG_FAILURE([no acceptable C compiler found in \$PATH])
   64 
   65 # Provide some information about the compiler.
   66 _AS_ECHO_LOG([checking for _AC_LANG compiler version])
   67 set X $ac_compile
   68 ac_compiler=$[2]
   69 for ac_option in --version -v -V -qversion -version; do
   70   _AC_DO_LIMIT([$ac_compiler $ac_option >&AS_MESSAGE_LOG_FD])
   71 done
   72 
   73 m4_expand_once([_AC_COMPILER_EXEEXT])[]dnl
   74 m4_expand_once([_AC_COMPILER_OBJEXT])[]dnl
   75 _AC_LANG_COMPILER_GNU
   76 if test $ac_compiler_gnu = yes; then
   77   GCC=yes
   78 else
   79   GCC=
   80 fi
   81 _AC_PROG_CC_G
   82 dnl
   83 dnl Set ac_prog_cc_stdc to the supported C version.
   84 dnl Also set the documented variable ac_cv_prog_cc_stdc;
   85 dnl its name was chosen when it was cached, but it is no longer cached.
   86 _AC_PROG_CC_C11([ac_prog_cc_stdc=c11
   87 		 ac_cv_prog_cc_stdc=$ac_cv_prog_cc_c11],
   88   [_AC_PROG_CC_C99([ac_prog_cc_stdc=c99
   89 		    ac_cv_prog_cc_stdc=$ac_cv_prog_cc_c99],
   90      [_AC_PROG_CC_C89([ac_prog_cc_stdc=c89
   91 		       ac_cv_prog_cc_stdc=$ac_cv_prog_cc_c89],
   92 		      [ac_prog_cc_stdc=no
   93 		       ac_cv_prog_cc_stdc=no])])])
   94 dnl
   95 AC_LANG_POP(C)dnl
   96 ])# AC_PROG_CC
   97 
   98 
   99 
  100 # AC_PROG_CXX([LIST-OF-COMPILERS])
  101 # --------------------------------
  102 # LIST-OF-COMPILERS is a space separated list of C++ compilers to search
  103 # for (if not specified, a default list is used).  This just gives the
  104 # user an opportunity to specify an alternative search list for the C++
  105 # compiler.
  106 # aCC	HP-UX C++ compiler much better than `CC', so test before.
  107 # FCC   Fujitsu C++ compiler
  108 # KCC	KAI C++ compiler
  109 # RCC	Rational C++
  110 # xlC_r	AIX C Set++ (with support for reentrant code)
  111 # xlC	AIX C Set++
  112 AC_DEFUN([AC_PROG_CXX],
  113 [AC_LANG_PUSH(C++)dnl
  114 AC_ARG_VAR([CXX],      [C++ compiler command])dnl
  115 AC_ARG_VAR([CXXFLAGS], [C++ compiler flags])dnl
  116 _AC_ARG_VAR_LDFLAGS()dnl
  117 _AC_ARG_VAR_LIBS()dnl
  118 _AC_ARG_VAR_CPPFLAGS()dnl
  119 _AC_ARG_VAR_PRECIOUS([CCC])dnl
  120 if test -z "$CXX"; then
  121   if test -n "$CCC"; then
  122     CXX=$CCC
  123   else
  124     AC_CHECK_TOOLS(CXX,
  125 		   [m4_default([$1],
  126 			       [g++ c++ gpp aCC CC cxx cc++ cl.exe FCC KCC RCC xlC_r xlC])],
  127 		   g++)
  128   fi
  129 fi
  130 # Provide some information about the compiler.
  131 _AS_ECHO_LOG([checking for _AC_LANG compiler version])
  132 set X $ac_compile
  133 ac_compiler=$[2]
  134 for ac_option in --version -v -V -qversion; do
  135   _AC_DO_LIMIT([$ac_compiler $ac_option >&AS_MESSAGE_LOG_FD])
  136 done
  137 
  138 m4_expand_once([_AC_COMPILER_EXEEXT])[]dnl
  139 m4_expand_once([_AC_COMPILER_OBJEXT])[]dnl
  140 _AC_LANG_COMPILER_GNU
  141 if test $ac_compiler_gnu = yes; then
  142   GXX=yes
  143 else
  144   GXX=
  145 fi
  146 _AC_PROG_CXX_G
  147 _AC_PROG_CXX_CXX11([ac_prog_cxx_stdcxx=cxx11
  148 		    ac_cv_prog_cxx_stdcxx=$ac_cv_prog_cxx_cxx11
  149 		    ac_cv_prog_cxx_cxx98=$ac_cv_prog_cxx_cxx11],
  150    [_AC_PROG_CXX_CXX98([ac_prog_cxx_stdcxx=cxx98
  151 		        ac_cv_prog_cxx_stdcxx=$ac_cv_prog_cxx_cxx98],
  152 		       [ac_prog_cxx_stdcxx=no
  153 		        ac_cv_prog_cxx_stdcxx=no])])
  154 AC_LANG_POP(C++)dnl
  155 ])# AC_PROG_CXX
  156 
  157 
  158 # _AC_C_STD_TRY(STANDARD, TEST-PROLOGUE, TEST-BODY, OPTION-LIST,
  159 #		ACTION-IF-AVAILABLE, ACTION-IF-UNAVAILABLE)
  160 # --------------------------------------------------------------
  161 # Check whether the C compiler accepts features of STANDARD (e.g `c89', `c99')
  162 # by trying to compile a program of TEST-PROLOGUE and TEST-BODY.  If this fails,
  163 # try again with each compiler option in the space-separated OPTION-LIST; if one
  164 # helps, append it to CC.  If eventually successful, run ACTION-IF-AVAILABLE,
  165 # else ACTION-IF-UNAVAILABLE.
  166 AC_DEFUN([_AC_C_STD_TRY],
  167 [AC_MSG_CHECKING([for $CC option to enable ]m4_translit($1, [c], [C])[ features])
  168 AC_CACHE_VAL(ac_cv_prog_cc_$1,
  169 [ac_cv_prog_cc_$1=no
  170 ac_save_CC=$CC
  171 AC_LANG_CONFTEST([AC_LANG_PROGRAM([$2], [$3])])
  172 for ac_arg in '' $4
  173 do
  174   CC="$ac_save_CC $ac_arg"
  175   _AC_COMPILE_IFELSE([], [ac_cv_prog_cc_$1=$ac_arg])
  176   test "x$ac_cv_prog_cc_$1" != "xno" && break
  177 done
  178 rm -f conftest.$ac_ext
  179 CC=$ac_save_CC
  180 ])# AC_CACHE_VAL
  181 ac_prog_cc_stdc_options=
  182 case "x$ac_cv_prog_cc_$1" in
  183   x)
  184     AC_MSG_RESULT([none needed]) ;;
  185   xno)
  186     AC_MSG_RESULT([unsupported]) ;;
  187   *)
  188     ac_prog_cc_stdc_options=" $ac_cv_prog_cc_$1"
  189     CC=$CC$ac_prog_cc_stdc_options
  190     AC_MSG_RESULT([$ac_cv_prog_cc_$1]) ;;
  191 esac
  192 AS_IF([test "x$ac_cv_prog_cc_$1" != xno], [$5], [$6])
  193 ])# _AC_C_STD_TRY
  194 
  195 # _AC_C_C99_TEST_HEADER
  196 # ---------------------
  197 # A C header suitable for testing for C99.
  198 AC_DEFUN([_AC_C_C99_TEST_HEADER],
  199 [[#include <stdarg.h>
  200 #include <stdbool.h>
  201 #include <stdlib.h>
  202 #include <wchar.h>
  203 #include <stdio.h>
  204 
  205 // Check varargs macros.  These examples are taken from C99 6.10.3.5.
  206 #define debug(...) fprintf (stderr, __VA_ARGS__)
  207 #define showlist(...) puts (#__VA_ARGS__)
  208 #define report(test,...) ((test) ? puts (#test) : printf (__VA_ARGS__))
  209 static void
  210 test_varargs_macros (void)
  211 {
  212   int x = 1234;
  213   int y = 5678;
  214   debug ("Flag");
  215   debug ("X = %d\n", x);
  216   showlist (The first, second, and third items.);
  217   report (x>y, "x is %d but y is %d", x, y);
  218 }
  219 
  220 // Check long long types.
  221 #define BIG64 18446744073709551615ull
  222 #define BIG32 4294967295ul
  223 #define BIG_OK (BIG64 / BIG32 == 4294967297ull && BIG64 % BIG32 == 0)
  224 #if !BIG_OK
  225   your preprocessor is broken;
  226 #endif
  227 #if BIG_OK
  228 #else
  229   your preprocessor is broken;
  230 #endif
  231 static long long int bignum = -9223372036854775807LL;
  232 static unsigned long long int ubignum = BIG64;
  233 
  234 struct incomplete_array
  235 {
  236   int datasize;
  237   double data[];
  238 };
  239 
  240 struct named_init {
  241   int number;
  242   const wchar_t *name;
  243   double average;
  244 };
  245 
  246 typedef const char *ccp;
  247 
  248 static inline int
  249 test_restrict (ccp restrict text)
  250 {
  251   // See if C++-style comments work.
  252   // Iterate through items via the restricted pointer.
  253   // Also check for declarations in for loops.
  254   for (unsigned int i = 0; *(text+i) != '\0'; ++i)
  255     continue;
  256   return 0;
  257 }
  258 
  259 // Check varargs and va_copy.
  260 static bool
  261 test_varargs (const char *format, ...)
  262 {
  263   va_list args;
  264   va_start (args, format);
  265   va_list args_copy;
  266   va_copy (args_copy, args);
  267 
  268   const char *str = "";
  269   int number = 0;
  270   float fnumber = 0;
  271 
  272   while (*format)
  273     {
  274       switch (*format++)
  275 	{
  276 	case 's': // string
  277 	  str = va_arg (args_copy, const char *);
  278 	  break;
  279 	case 'd': // int
  280 	  number = va_arg (args_copy, int);
  281 	  break;
  282 	case 'f': // float
  283 	  fnumber = va_arg (args_copy, double);
  284 	  break;
  285 	default:
  286 	  break;
  287 	}
  288     }
  289   va_end (args_copy);
  290   va_end (args);
  291 
  292   return *str && number && fnumber;
  293 }]])# _AC_C_C99_TEST_HEADER
  294 
  295 # _AC_C_C99_TEST_BODY
  296 # -------------------
  297 # A C body suitable for testing for C99, assuming the corresponding header.
  298 AC_DEFUN([_AC_C_C99_TEST_BODY],
  299 [[
  300   // Check bool.
  301   _Bool success = false;
  302 
  303   // Check restrict.
  304   if (test_restrict ("String literal") == 0)
  305     success = true;
  306   char *restrict newvar = "Another string";
  307 
  308   // Check varargs.
  309   success &= test_varargs ("s, d' f .", "string", 65, 34.234);
  310   test_varargs_macros ();
  311 
  312   // Check flexible array members.
  313   struct incomplete_array *ia =
  314     malloc (sizeof (struct incomplete_array) + (sizeof (double) * 10));
  315   ia->datasize = 10;
  316   for (int i = 0; i < ia->datasize; ++i)
  317     ia->data[i] = i * 1.234;
  318 
  319   // Check named initializers.
  320   struct named_init ni = {
  321     .number = 34,
  322     .name = L"Test wide string",
  323     .average = 543.34343,
  324   };
  325 
  326   ni.number = 58;
  327 
  328   int dynamic_array[ni.number];
  329   dynamic_array[ni.number - 1] = 543;
  330 
  331   // work around unused variable warnings
  332   return (!success || bignum == 0LL || ubignum == 0uLL || newvar[0] == 'x'
  333 	  || dynamic_array[ni.number - 1] != 543);
  334 ]])
  335 
  336 # _AC_PROG_CC_C99 ([ACTION-IF-AVAILABLE], [ACTION-IF-UNAVAILABLE])
  337 # ----------------------------------------------------------------
  338 # If the C compiler is not in ISO C99 mode by default, try to add an
  339 # option to output variable CC to make it so.  This macro tries
  340 # various options that select ISO C99 on some system or another.  It
  341 # considers the compiler to be in ISO C99 mode if it handles _Bool,
  342 # // comments, flexible array members, inline, long long int, mixed
  343 # code and declarations, named initialization of structs, restrict,
  344 # va_copy, varargs macros, variable declarations in for loops and
  345 # variable length arrays.
  346 AC_DEFUN([_AC_PROG_CC_C99],
  347 [_AC_C_STD_TRY([c99],
  348 [_AC_C_C99_TEST_HEADER],
  349 [_AC_C_C99_TEST_BODY],
  350 dnl Try
  351 dnl GCC		-std=gnu99 (unused restrictive modes: -std=c99 -std=iso9899:1999)
  352 dnl IBM XL C	-qlanglvl=extc1x (V12.1; does not pass C11 test)
  353 dnl IBM XL C	-qlanglvl=extc99
  354 dnl		(pre-V12.1; unused restrictive mode: -qlanglvl=stdc99)
  355 dnl HP cc	-AC99
  356 dnl Intel ICC	-std=c99, -c99 (deprecated)
  357 dnl IRIX	-c99
  358 dnl Solaris	-D_STDC_C99=
  359 dnl		cc's -xc99 option uses linker magic to define the external
  360 dnl		symbol __xpg4 as if by "int __xpg4 = 1;", which enables C99
  361 dnl		behavior for C library functions.  This is not wanted here,
  362 dnl		because it means that a single module compiled with -xc99
  363 dnl		alters C runtime behavior for the entire program, not for
  364 dnl		just the module.  Instead, define the (private) symbol
  365 dnl		_STDC_C99, which suppresses a bogus failure in <stdbool.h>.
  366 dnl		The resulting compiler passes the test case here, and that's
  367 dnl		good enough.  For more, please see the thread starting at:
  368 dnl            http://lists.gnu.org/archive/html/autoconf/2010-12/msg00059.html
  369 dnl Tru64	-c99
  370 dnl with extended modes being tried first.
  371 [[-std=gnu99 -std=c99 -c99 -AC99 -D_STDC_C99= -qlanglvl=extc1x -qlanglvl=extc99]], [$1], [$2])[]dnl
  372 ])# _AC_PROG_CC_C99
  373 
  374 
  375 # _AC_PROG_CC_C11 ([ACTION-IF-AVAILABLE], [ACTION-IF-UNAVAILABLE])
  376 # ----------------------------------------------------------------
  377 # If the C compiler is not in ISO C11 mode by default, try to add an
  378 # option to output variable CC to make it so.  This macro tries
  379 # various options that select ISO C11 on some system or another.  It
  380 # considers the compiler to be in ISO C11 mode if it handles _Alignas,
  381 # _Alignof, _Noreturn, _Static_assert, UTF-8 string literals,
  382 # duplicate typedefs, and anonymous structures and unions.
  383 AC_DEFUN([_AC_PROG_CC_C11],
  384 [_AC_C_STD_TRY([c11],
  385 [_AC_C_C99_TEST_HEADER[
  386 // Check _Alignas.
  387 char _Alignas (double) aligned_as_double;
  388 char _Alignas (0) no_special_alignment;
  389 extern char aligned_as_int;
  390 char _Alignas (0) _Alignas (int) aligned_as_int;
  391 
  392 // Check _Alignof.
  393 enum
  394 {
  395   int_alignment = _Alignof (int),
  396   int_array_alignment = _Alignof (int[100]),
  397   char_alignment = _Alignof (char)
  398 };
  399 _Static_assert (0 < -_Alignof (int), "_Alignof is signed");
  400 
  401 // Check _Noreturn.
  402 int _Noreturn does_not_return (void) { for (;;) continue; }
  403 
  404 // Check _Static_assert.
  405 struct test_static_assert
  406 {
  407   int x;
  408   _Static_assert (sizeof (int) <= sizeof (long int),
  409                   "_Static_assert does not work in struct");
  410   long int y;
  411 };
  412 
  413 // Check UTF-8 literals.
  414 #define u8 syntax error!
  415 char const utf8_literal[] = u8"happens to be ASCII" "another string";
  416 
  417 // Check duplicate typedefs.
  418 typedef long *long_ptr;
  419 typedef long int *long_ptr;
  420 typedef long_ptr long_ptr;
  421 
  422 // Anonymous structures and unions -- taken from C11 6.7.2.1 Example 1.
  423 struct anonymous
  424 {
  425   union {
  426     struct { int i; int j; };
  427     struct { int k; long int l; } w;
  428   };
  429   int m;
  430 } v1;
  431 ]],
  432 [_AC_C_C99_TEST_BODY[
  433   v1.i = 2;
  434   v1.w.k = 5;
  435   _Static_assert (&v1.i == &v1.w.k, "Anonymous union alignment botch");
  436 ]],
  437 dnl Try
  438 dnl GCC		-std=gnu11 (unused restrictive mode: -std=c11)
  439 dnl with extended modes being tried first.
  440 dnl
  441 dnl Do not try -qlanglvl=extc1x, because IBM XL C V12.1 (the latest version as
  442 dnl of September 2012) does not pass the C11 test.  For now, try extc1x when
  443 dnl compiling the C99 test instead, since it enables _Static_assert and
  444 dnl _Noreturn, which is a win.  If -qlanglvl=extc11 or -qlanglvl=extc1x passes
  445 dnl the C11 test in some future version of IBM XL C, we'll add it here,
  446 dnl preferably extc11.
  447 [[-std=gnu11]], [$1], [$2])[]dnl
  448 ])# _AC_PROG_CC_C11
  449 
  450 
  451 # AC_PROG_CC_C89
  452 # --------------
  453 # Do not use AU_ALIAS here and in AC_PROG_CC_C99 and AC_PROG_CC_STDC,
  454 # as that'd be incompatible with how Automake redefines AC_PROG_CC.  See
  455 # <http://lists.gnu.org/archive/html/autoconf/2012-10/msg00048.html>.
  456 AU_DEFUN([AC_PROG_CC_C89],
  457   [AC_REQUIRE([AC_PROG_CC])],
  458   [$0 is obsolete; use AC_PROG_CC]
  459 )
  460 
  461 # AC_PROG_CC_C99
  462 # --------------
  463 AU_DEFUN([AC_PROG_CC_C99],
  464   [AC_REQUIRE([AC_PROG_CC])],
  465   [$0 is obsolete; use AC_PROG_CC]
  466 )
  467 
  468 # AC_PROG_CC_STDC
  469 # ---------------
  470 AU_DEFUN([AC_PROG_CC_STDC],
  471   [AC_REQUIRE([AC_PROG_CC])],
  472   [$0 is obsolete; use AC_PROG_CC]
  473 )
  474 
  475 
  476 # AC_C_PROTOTYPES
  477 # ---------------
  478 # Check if the C compiler supports prototypes, included if it needs
  479 # options.
  480 AC_DEFUN([AC_C_PROTOTYPES],
  481 [AC_REQUIRE([AC_PROG_CC])dnl
  482 if test "$ac_prog_cc_stdc" != no; then
  483   AC_DEFINE(PROTOTYPES, 1,
  484 	    [Define to 1 if the C compiler supports function prototypes.])
  485   AC_DEFINE(__PROTOTYPES, 1,
  486 	    [Define like PROTOTYPES; this can be used by system headers.])
  487 fi
  488 ])# AC_C_PROTOTYPES
  489 
  490 
  491 # _AC_CXX_STD_TRY(STANDARD, TEST-PROLOGUE, TEST-BODY, OPTION-LIST,
  492 #		  ACTION-IF-AVAILABLE, ACTION-IF-UNAVAILABLE)
  493 # ----------------------------------------------------------------
  494 # Check whether the C++ compiler accepts features of STANDARD (e.g
  495 # `cxx98', `cxx11') by trying to compile a program of TEST-PROLOGUE
  496 # and TEST-BODY.  If this fails, try again with each compiler option
  497 # in the space-separated OPTION-LIST; if one helps, append it to CXX.
  498 # If eventually successful, run ACTION-IF-AVAILABLE, else
  499 # ACTION-IF-UNAVAILABLE.
  500 AC_DEFUN([_AC_CXX_STD_TRY],
  501 [AC_MSG_CHECKING([for $CXX option to enable ]m4_translit(m4_translit($1, [x], [+]), [a-z], [A-Z])[ features])
  502 AC_LANG_PUSH(C++)dnl
  503 AC_CACHE_VAL(ac_cv_prog_cxx_$1,
  504 [ac_cv_prog_cxx_$1=no
  505 ac_save_CXX=$CXX
  506 AC_LANG_CONFTEST([AC_LANG_PROGRAM([$2], [$3])])
  507 for ac_arg in '' $4
  508 do
  509   CXX="$ac_save_CXX $ac_arg"
  510   _AC_COMPILE_IFELSE([], [ac_cv_prog_cxx_$1=$ac_arg])
  511   test "x$ac_cv_prog_cxx_$1" != "xno" && break
  512 done
  513 rm -f conftest.$ac_ext
  514 CXX=$ac_save_CXX
  515 ])# AC_CACHE_VAL
  516 ac_prog_cxx_stdcxx_options=
  517 case "x$ac_cv_prog_cxx_$1" in
  518   x)
  519     AC_MSG_RESULT([none needed]) ;;
  520   xno)
  521     AC_MSG_RESULT([unsupported]) ;;
  522   *)
  523     ac_prog_cxx_stdcxx_options=" $ac_cv_prog_cxx_$1"
  524     CXX=$CXX$ac_prog_cxx_stdcxx_options
  525     AC_MSG_RESULT([$ac_cv_prog_cxx_$1]) ;;
  526 esac
  527 AC_LANG_POP(C++)dnl
  528 AS_IF([test "x$ac_cv_prog_cxx_$1" != xno], [$5], [$6])
  529 ])# _AC_CXX_STD_TRY
  530 
  531 # _AC_CXX_CXX98_TEST_HEADER
  532 # -------------------------
  533 # A C++ header suitable for testing for CXX98.
  534 AC_DEFUN([_AC_CXX_CXX98_TEST_HEADER],
  535 [[
  536 #include <algorithm>
  537 #include <cstdlib>
  538 #include <fstream>
  539 #include <iomanip>
  540 #include <iostream>
  541 #include <list>
  542 #include <map>
  543 #include <set>
  544 #include <sstream>
  545 #include <stdexcept>
  546 #include <string>
  547 #include <utility>
  548 #include <vector>
  549 
  550 namespace test {
  551   typedef std::vector<std::string> string_vec;
  552   typedef std::pair<int,bool> map_value;
  553   typedef std::map<std::string,map_value> map_type;
  554   typedef std::set<int> set_type;
  555 
  556   template<typename T>
  557   class printer {
  558   public:
  559     printer(std::ostringstream& os): os(os) {}
  560     void operator() (T elem) { os << elem << std::endl; }
  561   private:
  562     std::ostringstream& os;
  563   };
  564 }
  565 ]])# _AC_CXX_CXX98_TEST_HEADER
  566 
  567 # _AC_CXX_CXX98_TEST_BODY
  568 # -----------------------
  569 # A C++ body suitable for testing for CXX98, assuming the corresponding header.
  570 AC_DEFUN([_AC_CXX_CXX98_TEST_BODY],
  571 [[
  572 
  573 try {
  574   // Basic string.
  575   std::string teststr("ASCII text");
  576   teststr += " string";
  577 
  578   // Simple vector.
  579   test::string_vec testvec;
  580   testvec.push_back(teststr);
  581   testvec.push_back("foo");
  582   testvec.push_back("bar");
  583   if (testvec.size() != 3) {
  584     throw std::runtime_error("vector size is not 1");
  585   }
  586 
  587   // Dump vector into stringstream and obtain string.
  588   std::ostringstream os;
  589   for (test::string_vec::const_iterator i = testvec.begin();
  590        i != testvec.end(); ++i) {
  591     if (i + 1 != testvec.end()) {
  592       os << teststr << '\n';
  593     }
  594   }
  595   // Check algorithms work.
  596   std::for_each(testvec.begin(), testvec.end(), test::printer<std::string>(os));
  597   std::string os_out = os.str();
  598 
  599   // Test pair and map.
  600   test::map_type testmap;
  601   testmap.insert(std::make_pair(std::string("key"),
  602                                 std::make_pair(53,false)));
  603 
  604   // Test set.
  605   int values[] = {9, 7, 13, 15, 4, 18, 12, 10, 5, 3, 14, 19, 17, 8, 6, 20, 16, 2, 11, 1};
  606   test::set_type testset(values, values + sizeof(values)/sizeof(values[0]));
  607   std::list<int> testlist(testset.begin(), testset.end());
  608   std::copy(testset.begin(), testset.end(), std::back_inserter(testlist));
  609 } catch (const std::exception& e) {
  610   std::cerr << "Caught exception: " << e.what() << std::endl;
  611 
  612   // Test fstream
  613   std::ofstream of("test.txt");
  614   of << "Test ASCII text\n" << std::flush;
  615   of << "N= " << std::hex << std::setw(8) << std::left << 534 << std::endl;
  616   of.close();
  617 }
  618 std::exit(0);
  619 ]])
  620 
  621 # _AC_CXX_CXX11_TEST_HEADER
  622 # -------------------------
  623 # A C++ header suitable for testing for CXX11.
  624 AC_DEFUN([_AC_CXX_CXX11_TEST_HEADER],
  625 [[
  626 #include <deque>
  627 #include <functional>
  628 #include <memory>
  629 #include <tuple>
  630 #include <array>
  631 #include <regex>
  632 #include <iostream>
  633 
  634 namespace cxx11test
  635 {
  636   typedef std::shared_ptr<std::string> sptr;
  637   typedef std::weak_ptr<std::string> wptr;
  638 
  639   typedef std::tuple<std::string,int,double> tp;
  640   typedef std::array<int, 20> int_array;
  641 
  642   constexpr int get_val() { return 20; }
  643 
  644   struct testinit
  645   {
  646     int i;
  647     double d;
  648   };
  649 
  650   class delegate  {
  651   public:
  652     delegate(int n) : n(n) {}
  653     delegate(): delegate(2354) {}
  654 
  655     virtual int getval() { return this->n; };
  656   protected:
  657     int n;
  658   };
  659 
  660   class overridden : public delegate {
  661   public:
  662     overridden(int n): delegate(n) {}
  663     virtual int getval() override final { return this->n * 2; }
  664   };
  665 
  666   class nocopy {
  667   public:
  668     nocopy(int i): i(i) {}
  669     nocopy() = default;
  670     nocopy(const nocopy&) = delete;
  671     nocopy & operator=(const nocopy&) = delete;
  672   private:
  673     int i;
  674   };
  675 }
  676 ]])# _AC_CXX_CXX11_TEST_HEADER
  677 
  678 # _AC_CXX_CXX11_TEST_BODY
  679 # -----------------------
  680 # A C++ body suitable for testing for CXX11, assuming the corresponding header.
  681 AC_DEFUN([_AC_CXX_CXX11_TEST_BODY],
  682 [[
  683 {
  684   // Test auto and decltype
  685   std::deque<int> d;
  686   d.push_front(43);
  687   d.push_front(484);
  688   d.push_front(3);
  689   d.push_front(844);
  690   int total = 0;
  691   for (auto i = d.begin(); i != d.end(); ++i) { total += *i; }
  692 
  693   auto a1 = 6538;
  694   auto a2 = 48573953.4;
  695   auto a3 = "String literal";
  696 
  697   decltype(a2) a4 = 34895.034;
  698 }
  699 {
  700   // Test constexpr
  701   short sa[cxx11test::get_val()] = { 0 };
  702 }
  703 {
  704   // Test initialiser lists
  705   cxx11test::testinit il = { 4323, 435234.23544 };
  706 }
  707 {
  708   // Test range-based for and lambda
  709   cxx11test::int_array array = {9, 7, 13, 15, 4, 18, 12, 10, 5, 3, 14, 19, 17, 8, 6, 20, 16, 2, 11, 1};
  710   for (int &x : array) { x += 23; }
  711   std::for_each(array.begin(), array.end(), [](int v1){ std::cout << v1; });
  712 }
  713 {
  714   using cxx11test::sptr;
  715   using cxx11test::wptr;
  716 
  717   sptr sp(new std::string("ASCII string"));
  718   wptr wp(sp);
  719   sptr sp2(wp);
  720 }
  721 {
  722   cxx11test::tp tuple("test", 54, 45.53434);
  723   double d = std::get<2>(tuple);
  724   std::string s;
  725   int i;
  726   std::tie(s,i,d) = tuple;
  727 }
  728 {
  729   static std::regex filename_regex("^_?([a-z0-9_.]+-)+[a-z0-9]+$");
  730   std::string testmatch("Test if this string matches");
  731   bool match = std::regex_search(testmatch, filename_regex);
  732 }
  733 {
  734   cxx11test::int_array array = {9, 7, 13, 15, 4, 18, 12, 10, 5, 3, 14, 19, 17, 8, 6, 20, 16, 2, 11, 1};
  735   cxx11test::int_array::size_type size = array.size();
  736 }
  737 {
  738   // Test constructor delegation
  739   cxx11test::delegate d1;
  740   cxx11test::delegate d2();
  741   cxx11test::delegate d3(45);
  742 }
  743 {
  744   // Test override and final
  745   cxx11test::overridden o1(55464);
  746 }
  747 {
  748   // Test nullptr
  749   char *c = nullptr;
  750 }
  751 {
  752   // Test template brackets
  753   std::vector<std::pair<int,char*>> v1;
  754 }
  755 {
  756   // Unicode literals
  757   char *utf8 = u8"UTF-8 string \u2500";
  758   char16_t *utf16 = u"UTF-8 string \u2500";
  759   char32_t *utf32 = U"UTF-32 string \u2500";
  760 }
  761 ]])
  762 
  763 # _AC_PROG_CXX_CXX98 ([ACTION-IF-AVAILABLE], [ACTION-IF-UNAVAILABLE])
  764 # -------------------------------------------------------------------
  765 
  766 # If the C++ compiler is not in ISO C++98 mode by default, try to add
  767 # an option to output variable CXX to make it so.  This macro tries
  768 # various options that select ISO C++98 on some system or another.  It
  769 # considers the compiler to be in ISO C++98 mode if it handles basic
  770 # features of the std namespace including: string, containers (list,
  771 # map, set, vector), streams (fstreams, iostreams, stringstreams,
  772 # iomanip), pair, exceptions and algorithms.
  773 
  774 
  775 AC_DEFUN([_AC_PROG_CXX_CXX98],
  776 [_AC_CXX_STD_TRY([cxx98],
  777 [_AC_CXX_CXX98_TEST_HEADER],
  778 [_AC_CXX_CXX98_TEST_BODY],
  779 dnl Try
  780 dnl GCC		-std=gnu++98 (unused restrictive mode: -std=c++98)
  781 dnl IBM XL C	-qlanglvl=extended
  782 dnl HP aC++	-AA
  783 dnl Intel ICC	-std=gnu++98
  784 dnl Solaris	N/A (default)
  785 dnl Tru64	N/A (default, but -std gnu could be used)
  786 dnl with extended modes being tried first.
  787 [[-std=gnu++98 -std=c++98 -qlanglvl=extended -AA]], [$1], [$2])[]dnl
  788 ])# _AC_PROG_CXX_CXX98
  789 
  790 # _AC_PROG_CXX_CXX11 ([ACTION-IF-AVAILABLE], [ACTION-IF-UNAVAILABLE])
  791 # -------------------------------------------------------------------
  792 # If the C++ compiler is not in ISO CXX11 mode by default, try to add
  793 # an option to output variable CXX to make it so.  This macro tries
  794 # various options that select ISO C++11 on some system or another.  It
  795 # considers the compiler to be in ISO C++11 mode if it handles all the
  796 # tests from the C++98 checks, plus the following: Language features
  797 # (auto, constexpr, decltype, default/deleted constructors, delegate
  798 # constructors, final, initialiser lists, lambda functions, nullptr,
  799 # override, range-based for loops, template brackets without spaces,
  800 # unicode literals) and library features (array, memory (shared_ptr,
  801 # weak_ptr), regex and tuple types).
  802 AC_DEFUN([_AC_PROG_CXX_CXX11],
  803 [_AC_CXX_STD_TRY([cxx11],
  804 [_AC_CXX_CXX11_TEST_HEADER
  805 _AC_CXX_CXX98_TEST_HEADER],
  806 [_AC_CXX_CXX11_TEST_BODY
  807 _AC_CXX_CXX98_TEST_BODY],
  808 dnl Try
  809 dnl GCC		-std=gnu++11 (unused restrictive mode: -std=c++11) [and 0x variants]
  810 dnl IBM XL C	-qlanglvl=extended0x
  811 dnl		(pre-V12.1; unused restrictive mode: -qlanglvl=stdcxx11)
  812 dnl HP aC++	-AA
  813 dnl Intel ICC	-std=c++11 -std=c++0x
  814 dnl Solaris	N/A (no support)
  815 dnl Tru64	N/A (no support)
  816 dnl with extended modes being tried first.
  817 [[-std=gnu++11 -std=c++11 -std=gnu++0x -std=c++0x -qlanglvl=extended0x -AA]], [$1], [$2])[]dnl
  818 ])# _AC_PROG_CXX_CXX11