Blame m4/std-gnu11.m4

Packit 709fb3
# Prefer GNU C11 and C++11 to earlier versions.  -*- coding: utf-8 -*-
Packit 709fb3
Packit 709fb3
# This implementation is taken from GNU Autoconf lib/autoconf/c.m4
Packit 709fb3
# commit 017d5ddd82854911f0119691d91ea8a1438824d6
Packit 709fb3
# dated Sun Apr 3 13:57:17 2016 -0700
Packit 709fb3
# This implementation will be obsolete once we can assume Autoconf 2.70
Packit 709fb3
# or later is installed everywhere a Gnulib program might be developed.
Packit 709fb3
Packit 709fb3
Packit 709fb3
# Copyright (C) 2001-2017 Free Software Foundation, Inc.
Packit 709fb3
Packit 709fb3
# This program is free software; you can redistribute it and/or modify
Packit 709fb3
# it under the terms of the GNU General Public License as published by
Packit 709fb3
# the Free Software Foundation, either version 3 of the License, or
Packit 709fb3
# (at your option) any later version.
Packit 709fb3
#
Packit 709fb3
# This program is distributed in the hope that it will be useful,
Packit 709fb3
# but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 709fb3
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Packit 709fb3
# GNU General Public License for more details.
Packit 709fb3
#
Packit 709fb3
# You should have received a copy of the GNU General Public License
Packit 709fb3
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
Packit 709fb3
Packit 709fb3
# Written by David MacKenzie, with help from
Packit 709fb3
# Akim Demaille, Paul Eggert,
Packit 709fb3
# François Pinard, Karl Berry, Richard Pixley, Ian Lance Taylor,
Packit 709fb3
# Roland McGrath, Noah Friedman, david d zuhn, and many others.
Packit 709fb3
Packit 709fb3
Packit 709fb3
# AC_PROG_CC([COMPILER ...])
Packit 709fb3
# --------------------------
Packit 709fb3
# COMPILER ... is a space separated list of C compilers to search for.
Packit 709fb3
# This just gives the user an opportunity to specify an alternative
Packit 709fb3
# search list for the C compiler.
Packit 709fb3
AC_DEFUN_ONCE([AC_PROG_CC],
Packit 709fb3
[AC_LANG_PUSH(C)dnl
Packit 709fb3
AC_ARG_VAR([CC],     [C compiler command])dnl
Packit 709fb3
AC_ARG_VAR([CFLAGS], [C compiler flags])dnl
Packit 709fb3
_AC_ARG_VAR_LDFLAGS()dnl
Packit 709fb3
_AC_ARG_VAR_LIBS()dnl
Packit 709fb3
_AC_ARG_VAR_CPPFLAGS()dnl
Packit 709fb3
m4_ifval([$1],
Packit 709fb3
      [AC_CHECK_TOOLS(CC, [$1])],
Packit 709fb3
[AC_CHECK_TOOL(CC, gcc)
Packit 709fb3
if test -z "$CC"; then
Packit 709fb3
  dnl Here we want:
Packit 709fb3
  dnl	AC_CHECK_TOOL(CC, cc)
Packit 709fb3
  dnl but without the check for a tool without the prefix.
Packit 709fb3
  dnl Until the check is removed from there, copy the code:
Packit 709fb3
  if test -n "$ac_tool_prefix"; then
Packit 709fb3
    AC_CHECK_PROG(CC, [${ac_tool_prefix}cc], [${ac_tool_prefix}cc])
Packit 709fb3
  fi
Packit 709fb3
fi
Packit 709fb3
if test -z "$CC"; then
Packit 709fb3
  AC_CHECK_PROG(CC, cc, cc, , , /usr/ucb/cc)
Packit 709fb3
fi
Packit 709fb3
if test -z "$CC"; then
Packit 709fb3
  AC_CHECK_TOOLS(CC, cl.exe)
Packit 709fb3
fi
Packit 709fb3
if test -z "$CC"; then
Packit 709fb3
  AC_CHECK_TOOL(CC, clang)
Packit 709fb3
fi
Packit 709fb3
])
Packit 709fb3
Packit 709fb3
test -z "$CC" && AC_MSG_FAILURE([no acceptable C compiler found in \$PATH])
Packit 709fb3
Packit 709fb3
# Provide some information about the compiler.
Packit 709fb3
_AS_ECHO_LOG([checking for _AC_LANG compiler version])
Packit 709fb3
set X $ac_compile
Packit 709fb3
ac_compiler=$[2]
Packit 709fb3
for ac_option in --version -v -V -qversion -version; do
Packit 709fb3
  _AC_DO_LIMIT([$ac_compiler $ac_option >&AS_MESSAGE_LOG_FD])
Packit 709fb3
done
Packit 709fb3
Packit 709fb3
m4_expand_once([_AC_COMPILER_EXEEXT])[]dnl
Packit 709fb3
m4_expand_once([_AC_COMPILER_OBJEXT])[]dnl
Packit 709fb3
_AC_LANG_COMPILER_GNU
Packit 709fb3
if test $ac_compiler_gnu = yes; then
Packit 709fb3
  GCC=yes
Packit 709fb3
else
Packit 709fb3
  GCC=
Packit 709fb3
fi
Packit 709fb3
_AC_PROG_CC_G
Packit 709fb3
dnl
Packit 709fb3
dnl Set ac_prog_cc_stdc to the supported C version.
Packit 709fb3
dnl Also set the documented variable ac_cv_prog_cc_stdc;
Packit 709fb3
dnl its name was chosen when it was cached, but it is no longer cached.
Packit 709fb3
_AC_PROG_CC_C11([ac_prog_cc_stdc=c11
Packit 709fb3
		 ac_cv_prog_cc_stdc=$ac_cv_prog_cc_c11],
Packit 709fb3
  [_AC_PROG_CC_C99([ac_prog_cc_stdc=c99
Packit 709fb3
		    ac_cv_prog_cc_stdc=$ac_cv_prog_cc_c99],
Packit 709fb3
     [_AC_PROG_CC_C89([ac_prog_cc_stdc=c89
Packit 709fb3
		       ac_cv_prog_cc_stdc=$ac_cv_prog_cc_c89],
Packit 709fb3
		      [ac_prog_cc_stdc=no
Packit 709fb3
		       ac_cv_prog_cc_stdc=no])])])
Packit 709fb3
dnl
Packit 709fb3
AC_LANG_POP(C)dnl
Packit 709fb3
])# AC_PROG_CC
Packit 709fb3
Packit 709fb3
Packit 709fb3
Packit 709fb3
# AC_PROG_CXX([LIST-OF-COMPILERS])
Packit 709fb3
# --------------------------------
Packit 709fb3
# LIST-OF-COMPILERS is a space separated list of C++ compilers to search
Packit 709fb3
# for (if not specified, a default list is used).  This just gives the
Packit 709fb3
# user an opportunity to specify an alternative search list for the C++
Packit 709fb3
# compiler.
Packit 709fb3
# aCC	HP-UX C++ compiler much better than `CC', so test before.
Packit 709fb3
# FCC   Fujitsu C++ compiler
Packit 709fb3
# KCC	KAI C++ compiler
Packit 709fb3
# RCC	Rational C++
Packit 709fb3
# xlC_r	AIX C Set++ (with support for reentrant code)
Packit 709fb3
# xlC	AIX C Set++
Packit 709fb3
AC_DEFUN([AC_PROG_CXX],
Packit 709fb3
[AC_LANG_PUSH(C++)dnl
Packit 709fb3
AC_ARG_VAR([CXX],      [C++ compiler command])dnl
Packit 709fb3
AC_ARG_VAR([CXXFLAGS], [C++ compiler flags])dnl
Packit 709fb3
_AC_ARG_VAR_LDFLAGS()dnl
Packit 709fb3
_AC_ARG_VAR_LIBS()dnl
Packit 709fb3
_AC_ARG_VAR_CPPFLAGS()dnl
Packit 709fb3
_AC_ARG_VAR_PRECIOUS([CCC])dnl
Packit 709fb3
if test -z "$CXX"; then
Packit 709fb3
  if test -n "$CCC"; then
Packit 709fb3
    CXX=$CCC
Packit 709fb3
  else
Packit 709fb3
    AC_CHECK_TOOLS(CXX,
Packit 709fb3
		   [m4_default([$1],
Packit 709fb3
			       [g++ c++ gpp aCC CC cxx cc++ cl.exe FCC KCC RCC xlC_r xlC clang++])],
Packit 709fb3
		   g++)
Packit 709fb3
  fi
Packit 709fb3
fi
Packit 709fb3
# Provide some information about the compiler.
Packit 709fb3
_AS_ECHO_LOG([checking for _AC_LANG compiler version])
Packit 709fb3
set X $ac_compile
Packit 709fb3
ac_compiler=$[2]
Packit 709fb3
for ac_option in --version -v -V -qversion; do
Packit 709fb3
  _AC_DO_LIMIT([$ac_compiler $ac_option >&AS_MESSAGE_LOG_FD])
Packit 709fb3
done
Packit 709fb3
Packit 709fb3
m4_expand_once([_AC_COMPILER_EXEEXT])[]dnl
Packit 709fb3
m4_expand_once([_AC_COMPILER_OBJEXT])[]dnl
Packit 709fb3
_AC_LANG_COMPILER_GNU
Packit 709fb3
if test $ac_compiler_gnu = yes; then
Packit 709fb3
  GXX=yes
Packit 709fb3
else
Packit 709fb3
  GXX=
Packit 709fb3
fi
Packit 709fb3
_AC_PROG_CXX_G
Packit 709fb3
_AC_PROG_CXX_CXX11([ac_prog_cxx_stdcxx=cxx11
Packit 709fb3
		    ac_cv_prog_cxx_stdcxx=$ac_cv_prog_cxx_cxx11
Packit 709fb3
		    ac_cv_prog_cxx_cxx98=$ac_cv_prog_cxx_cxx11],
Packit 709fb3
   [_AC_PROG_CXX_CXX98([ac_prog_cxx_stdcxx=cxx98
Packit 709fb3
		        ac_cv_prog_cxx_stdcxx=$ac_cv_prog_cxx_cxx98],
Packit 709fb3
		       [ac_prog_cxx_stdcxx=no
Packit 709fb3
		        ac_cv_prog_cxx_stdcxx=no])])
Packit 709fb3
AC_LANG_POP(C++)dnl
Packit 709fb3
])# AC_PROG_CXX
Packit 709fb3
Packit 709fb3
Packit 709fb3
# _AC_C_STD_TRY(STANDARD, TEST-PROLOGUE, TEST-BODY, OPTION-LIST,
Packit 709fb3
#		ACTION-IF-AVAILABLE, ACTION-IF-UNAVAILABLE)
Packit 709fb3
# --------------------------------------------------------------
Packit 709fb3
# Check whether the C compiler accepts features of STANDARD (e.g `c89', `c99')
Packit 709fb3
# by trying to compile a program of TEST-PROLOGUE and TEST-BODY.  If this fails,
Packit 709fb3
# try again with each compiler option in the space-separated OPTION-LIST; if one
Packit 709fb3
# helps, append it to CC.  If eventually successful, run ACTION-IF-AVAILABLE,
Packit 709fb3
# else ACTION-IF-UNAVAILABLE.
Packit 709fb3
AC_DEFUN([_AC_C_STD_TRY],
Packit 709fb3
[AC_MSG_CHECKING([for $CC option to enable ]m4_translit($1, [c], [C])[ features])
Packit 709fb3
AC_CACHE_VAL(ac_cv_prog_cc_$1,
Packit 709fb3
[ac_cv_prog_cc_$1=no
Packit 709fb3
ac_save_CC=$CC
Packit 709fb3
AC_LANG_CONFTEST([AC_LANG_PROGRAM([$2], [$3])])
Packit 709fb3
for ac_arg in '' $4
Packit 709fb3
do
Packit 709fb3
  CC="$ac_save_CC $ac_arg"
Packit 709fb3
  _AC_COMPILE_IFELSE([], [ac_cv_prog_cc_$1=$ac_arg])
Packit 709fb3
  test "x$ac_cv_prog_cc_$1" != "xno" && break
Packit 709fb3
done
Packit 709fb3
rm -f conftest.$ac_ext
Packit 709fb3
CC=$ac_save_CC
Packit 709fb3
])# AC_CACHE_VAL
Packit 709fb3
ac_prog_cc_stdc_options=
Packit 709fb3
case "x$ac_cv_prog_cc_$1" in
Packit 709fb3
  x)
Packit 709fb3
    AC_MSG_RESULT([none needed]) ;;
Packit 709fb3
  xno)
Packit 709fb3
    AC_MSG_RESULT([unsupported]) ;;
Packit 709fb3
  *)
Packit 709fb3
    ac_prog_cc_stdc_options=" $ac_cv_prog_cc_$1"
Packit 709fb3
    CC=$CC$ac_prog_cc_stdc_options
Packit 709fb3
    AC_MSG_RESULT([$ac_cv_prog_cc_$1]) ;;
Packit 709fb3
esac
Packit 709fb3
AS_IF([test "x$ac_cv_prog_cc_$1" != xno], [$5], [$6])
Packit 709fb3
])# _AC_C_STD_TRY
Packit 709fb3
Packit 709fb3
# _AC_C_C99_TEST_HEADER
Packit 709fb3
# ---------------------
Packit 709fb3
# A C header suitable for testing for C99.
Packit 709fb3
AC_DEFUN([_AC_C_C99_TEST_HEADER],
Packit 709fb3
[[#include <stdarg.h>
Packit 709fb3
#include <stdbool.h>
Packit 709fb3
#include <stddef.h>
Packit 709fb3
#include <stdlib.h>
Packit 709fb3
#include <wchar.h>
Packit 709fb3
#include <stdio.h>
Packit 709fb3
Packit 709fb3
// Check varargs macros.  These examples are taken from C99 6.10.3.5.
Packit 709fb3
#define debug(...) fprintf (stderr, __VA_ARGS__)
Packit 709fb3
#define showlist(...) puts (#__VA_ARGS__)
Packit 709fb3
#define report(test,...) ((test) ? puts (#test) : printf (__VA_ARGS__))
Packit 709fb3
static void
Packit 709fb3
test_varargs_macros (void)
Packit 709fb3
{
Packit 709fb3
  int x = 1234;
Packit 709fb3
  int y = 5678;
Packit 709fb3
  debug ("Flag");
Packit 709fb3
  debug ("X = %d\n", x);
Packit 709fb3
  showlist (The first, second, and third items.);
Packit 709fb3
  report (x>y, "x is %d but y is %d", x, y);
Packit 709fb3
}
Packit 709fb3
Packit 709fb3
// Check long long types.
Packit 709fb3
#define BIG64 18446744073709551615ull
Packit 709fb3
#define BIG32 4294967295ul
Packit 709fb3
#define BIG_OK (BIG64 / BIG32 == 4294967297ull && BIG64 % BIG32 == 0)
Packit 709fb3
#if !BIG_OK
Packit 709fb3
  your preprocessor is broken;
Packit 709fb3
#endif
Packit 709fb3
#if BIG_OK
Packit 709fb3
#else
Packit 709fb3
  your preprocessor is broken;
Packit 709fb3
#endif
Packit 709fb3
static long long int bignum = -9223372036854775807LL;
Packit 709fb3
static unsigned long long int ubignum = BIG64;
Packit 709fb3
Packit 709fb3
struct incomplete_array
Packit 709fb3
{
Packit 709fb3
  int datasize;
Packit 709fb3
  double data[];
Packit 709fb3
};
Packit 709fb3
Packit 709fb3
struct named_init {
Packit 709fb3
  int number;
Packit 709fb3
  const wchar_t *name;
Packit 709fb3
  double average;
Packit 709fb3
};
Packit 709fb3
Packit 709fb3
typedef const char *ccp;
Packit 709fb3
Packit 709fb3
static inline int
Packit 709fb3
test_restrict (ccp restrict text)
Packit 709fb3
{
Packit 709fb3
  // See if C++-style comments work.
Packit 709fb3
  // Iterate through items via the restricted pointer.
Packit 709fb3
  // Also check for declarations in for loops.
Packit 709fb3
  for (unsigned int i = 0; *(text+i) != '\0'; ++i)
Packit 709fb3
    continue;
Packit 709fb3
  return 0;
Packit 709fb3
}
Packit 709fb3
Packit 709fb3
// Check varargs and va_copy.
Packit 709fb3
static bool
Packit 709fb3
test_varargs (const char *format, ...)
Packit 709fb3
{
Packit 709fb3
  va_list args;
Packit 709fb3
  va_start (args, format);
Packit 709fb3
  va_list args_copy;
Packit 709fb3
  va_copy (args_copy, args);
Packit 709fb3
Packit 709fb3
  const char *str = "";
Packit 709fb3
  int number = 0;
Packit 709fb3
  float fnumber = 0;
Packit 709fb3
Packit 709fb3
  while (*format)
Packit 709fb3
    {
Packit 709fb3
      switch (*format++)
Packit 709fb3
	{
Packit 709fb3
	case 's': // string
Packit 709fb3
	  str = va_arg (args_copy, const char *);
Packit 709fb3
	  break;
Packit 709fb3
	case 'd': // int
Packit 709fb3
	  number = va_arg (args_copy, int);
Packit 709fb3
	  break;
Packit 709fb3
	case 'f': // float
Packit 709fb3
	  fnumber = va_arg (args_copy, double);
Packit 709fb3
	  break;
Packit 709fb3
	default:
Packit 709fb3
	  break;
Packit 709fb3
	}
Packit 709fb3
    }
Packit 709fb3
  va_end (args_copy);
Packit 709fb3
  va_end (args);
Packit 709fb3
Packit 709fb3
  return *str && number && fnumber;
Packit 709fb3
}]])# _AC_C_C99_TEST_HEADER
Packit 709fb3
Packit 709fb3
# _AC_C_C99_TEST_BODY
Packit 709fb3
# -------------------
Packit 709fb3
# A C body suitable for testing for C99, assuming the corresponding header.
Packit 709fb3
AC_DEFUN([_AC_C_C99_TEST_BODY],
Packit 709fb3
[[
Packit 709fb3
  // Check bool.
Packit 709fb3
  _Bool success = false;
Packit 709fb3
Packit 709fb3
  // Check restrict.
Packit 709fb3
  if (test_restrict ("String literal") == 0)
Packit 709fb3
    success = true;
Packit 709fb3
  char *restrict newvar = "Another string";
Packit 709fb3
Packit 709fb3
  // Check varargs.
Packit 709fb3
  success &= test_varargs ("s, d' f .", "string", 65, 34.234);
Packit 709fb3
  test_varargs_macros ();
Packit 709fb3
Packit 709fb3
  // Check flexible array members.
Packit 709fb3
  struct incomplete_array *ia =
Packit 709fb3
    malloc (sizeof (struct incomplete_array) + (sizeof (double) * 10));
Packit 709fb3
  ia->datasize = 10;
Packit 709fb3
  for (int i = 0; i < ia->datasize; ++i)
Packit 709fb3
    ia->data[i] = i * 1.234;
Packit 709fb3
Packit 709fb3
  // Check named initializers.
Packit 709fb3
  struct named_init ni = {
Packit 709fb3
    .number = 34,
Packit 709fb3
    .name = L"Test wide string",
Packit 709fb3
    .average = 543.34343,
Packit 709fb3
  };
Packit 709fb3
Packit 709fb3
  ni.number = 58;
Packit 709fb3
Packit 709fb3
  int dynamic_array[ni.number];
Packit 709fb3
  dynamic_array[ni.number - 1] = 543;
Packit 709fb3
Packit 709fb3
  // work around unused variable warnings
Packit 709fb3
  return (!success || bignum == 0LL || ubignum == 0uLL || newvar[0] == 'x'
Packit 709fb3
	  || dynamic_array[ni.number - 1] != 543);
Packit 709fb3
]])
Packit 709fb3
Packit 709fb3
# _AC_PROG_CC_C99 ([ACTION-IF-AVAILABLE], [ACTION-IF-UNAVAILABLE])
Packit 709fb3
# ----------------------------------------------------------------
Packit 709fb3
# If the C compiler is not in ISO C99 mode by default, try to add an
Packit 709fb3
# option to output variable CC to make it so.  This macro tries
Packit 709fb3
# various options that select ISO C99 on some system or another.  It
Packit 709fb3
# considers the compiler to be in ISO C99 mode if it handles _Bool,
Packit 709fb3
# // comments, flexible array members, inline, long long int, mixed
Packit 709fb3
# code and declarations, named initialization of structs, restrict,
Packit 709fb3
# va_copy, varargs macros, variable declarations in for loops and
Packit 709fb3
# variable length arrays.
Packit 709fb3
AC_DEFUN([_AC_PROG_CC_C99],
Packit 709fb3
[_AC_C_STD_TRY([c99],
Packit 709fb3
[_AC_C_C99_TEST_HEADER],
Packit 709fb3
[_AC_C_C99_TEST_BODY],
Packit 709fb3
dnl Try
Packit 709fb3
dnl GCC		-std=gnu99 (unused restrictive modes: -std=c99 -std=iso9899:1999)
Packit 709fb3
dnl IBM XL C	-qlanglvl=extc1x (V12.1; does not pass C11 test)
Packit 709fb3
dnl IBM XL C	-qlanglvl=extc99
Packit 709fb3
dnl		(pre-V12.1; unused restrictive mode: -qlanglvl=stdc99)
Packit 709fb3
dnl HP cc	-AC99
Packit 709fb3
dnl Intel ICC	-std=c99, -c99 (deprecated)
Packit 709fb3
dnl IRIX	-c99
Packit 709fb3
dnl Solaris	-D_STDC_C99=
Packit 709fb3
dnl		cc's -xc99 option uses linker magic to define the external
Packit 709fb3
dnl		symbol __xpg4 as if by "int __xpg4 = 1;", which enables C99
Packit 709fb3
dnl		behavior for C library functions.  This is not wanted here,
Packit 709fb3
dnl		because it means that a single module compiled with -xc99
Packit 709fb3
dnl		alters C runtime behavior for the entire program, not for
Packit 709fb3
dnl		just the module.  Instead, define the (private) symbol
Packit 709fb3
dnl		_STDC_C99, which suppresses a bogus failure in <stdbool.h>.
Packit 709fb3
dnl		The resulting compiler passes the test case here, and that's
Packit 709fb3
dnl		good enough.  For more, please see the thread starting at:
Packit 709fb3
dnl            http://lists.gnu.org/archive/html/autoconf/2010-12/msg00059.html
Packit 709fb3
dnl Tru64	-c99
Packit 709fb3
dnl with extended modes being tried first.
Packit 709fb3
[[-std=gnu99 -std=c99 -c99 -AC99 -D_STDC_C99= -qlanglvl=extc1x -qlanglvl=extc99]], [$1], [$2])[]dnl
Packit 709fb3
])# _AC_PROG_CC_C99
Packit 709fb3
Packit 709fb3
Packit 709fb3
# _AC_PROG_CC_C11 ([ACTION-IF-AVAILABLE], [ACTION-IF-UNAVAILABLE])
Packit 709fb3
# ----------------------------------------------------------------
Packit 709fb3
# If the C compiler is not in ISO C11 mode by default, try to add an
Packit 709fb3
# option to output variable CC to make it so.  This macro tries
Packit 709fb3
# various options that select ISO C11 on some system or another.  It
Packit 709fb3
# considers the compiler to be in ISO C11 mode if it handles _Alignas,
Packit 709fb3
# _Alignof, _Noreturn, _Static_assert, UTF-8 string literals,
Packit 709fb3
# duplicate typedefs, and anonymous structures and unions.
Packit 709fb3
AC_DEFUN([_AC_PROG_CC_C11],
Packit 709fb3
[_AC_C_STD_TRY([c11],
Packit 709fb3
[_AC_C_C99_TEST_HEADER[
Packit 709fb3
// Check _Alignas.
Packit 709fb3
char _Alignas (double) aligned_as_double;
Packit 709fb3
char _Alignas (0) no_special_alignment;
Packit 709fb3
extern char aligned_as_int;
Packit 709fb3
char _Alignas (0) _Alignas (int) aligned_as_int;
Packit 709fb3
Packit 709fb3
// Check _Alignof.
Packit 709fb3
enum
Packit 709fb3
{
Packit 709fb3
  int_alignment = _Alignof (int),
Packit 709fb3
  int_array_alignment = _Alignof (int[100]),
Packit 709fb3
  char_alignment = _Alignof (char)
Packit 709fb3
};
Packit 709fb3
_Static_assert (0 < -_Alignof (int), "_Alignof is signed");
Packit 709fb3
Packit 709fb3
// Check _Noreturn.
Packit 709fb3
int _Noreturn does_not_return (void) { for (;;) continue; }
Packit 709fb3
Packit 709fb3
// Check _Static_assert.
Packit 709fb3
struct test_static_assert
Packit 709fb3
{
Packit 709fb3
  int x;
Packit 709fb3
  _Static_assert (sizeof (int) <= sizeof (long int),
Packit 709fb3
                  "_Static_assert does not work in struct");
Packit 709fb3
  long int y;
Packit 709fb3
};
Packit 709fb3
Packit 709fb3
// Check UTF-8 literals.
Packit 709fb3
#define u8 syntax error!
Packit 709fb3
char const utf8_literal[] = u8"happens to be ASCII" "another string";
Packit 709fb3
Packit 709fb3
// Check duplicate typedefs.
Packit 709fb3
typedef long *long_ptr;
Packit 709fb3
typedef long int *long_ptr;
Packit 709fb3
typedef long_ptr long_ptr;
Packit 709fb3
Packit 709fb3
// Anonymous structures and unions -- taken from C11 6.7.2.1 Example 1.
Packit 709fb3
struct anonymous
Packit 709fb3
{
Packit 709fb3
  union {
Packit 709fb3
    struct { int i; int j; };
Packit 709fb3
    struct { int k; long int l; } w;
Packit 709fb3
  };
Packit 709fb3
  int m;
Packit 709fb3
} v1;
Packit 709fb3
]],
Packit 709fb3
[_AC_C_C99_TEST_BODY[
Packit 709fb3
  v1.i = 2;
Packit 709fb3
  v1.w.k = 5;
Packit 709fb3
  _Static_assert ((offsetof (struct anonymous, i)
Packit 709fb3
		   == offsetof (struct anonymous, w.k)),
Packit 709fb3
		  "Anonymous union alignment botch");
Packit 709fb3
]],
Packit 709fb3
dnl Try
Packit 709fb3
dnl GCC		-std=gnu11 (unused restrictive mode: -std=c11)
Packit 709fb3
dnl with extended modes being tried first.
Packit 709fb3
dnl
Packit 709fb3
dnl Do not try -qlanglvl=extc1x, because IBM XL C V12.1 (the latest version as
Packit 709fb3
dnl of September 2012) does not pass the C11 test.  For now, try extc1x when
Packit 709fb3
dnl compiling the C99 test instead, since it enables _Static_assert and
Packit 709fb3
dnl _Noreturn, which is a win.  If -qlanglvl=extc11 or -qlanglvl=extc1x passes
Packit 709fb3
dnl the C11 test in some future version of IBM XL C, we'll add it here,
Packit 709fb3
dnl preferably extc11.
Packit 709fb3
[[-std=gnu11]], [$1], [$2])[]dnl
Packit 709fb3
])# _AC_PROG_CC_C11
Packit 709fb3
Packit 709fb3
Packit 709fb3
# AC_PROG_CC_C89
Packit 709fb3
# --------------
Packit 709fb3
# Do not use AU_ALIAS here and in AC_PROG_CC_C99 and AC_PROG_CC_STDC,
Packit 709fb3
# as that'd be incompatible with how Automake redefines AC_PROG_CC.  See
Packit 709fb3
# <http://lists.gnu.org/archive/html/autoconf/2012-10/msg00048.html>.
Packit 709fb3
AU_DEFUN([AC_PROG_CC_C89],
Packit 709fb3
  [AC_REQUIRE([AC_PROG_CC])],
Packit 709fb3
  [$0 is obsolete; use AC_PROG_CC]
Packit 709fb3
)
Packit 709fb3
Packit 709fb3
# AC_PROG_CC_C99
Packit 709fb3
# --------------
Packit 709fb3
AU_DEFUN([AC_PROG_CC_C99],
Packit 709fb3
  [AC_REQUIRE([AC_PROG_CC])],
Packit 709fb3
  [$0 is obsolete; use AC_PROG_CC]
Packit 709fb3
)
Packit 709fb3
Packit 709fb3
# AC_PROG_CC_STDC
Packit 709fb3
# ---------------
Packit 709fb3
AU_DEFUN([AC_PROG_CC_STDC],
Packit 709fb3
  [AC_REQUIRE([AC_PROG_CC])],
Packit 709fb3
  [$0 is obsolete; use AC_PROG_CC]
Packit 709fb3
)
Packit 709fb3
Packit 709fb3
Packit 709fb3
# AC_C_PROTOTYPES
Packit 709fb3
# ---------------
Packit 709fb3
# Check if the C compiler supports prototypes, included if it needs
Packit 709fb3
# options.
Packit 709fb3
AC_DEFUN([AC_C_PROTOTYPES],
Packit 709fb3
[AC_REQUIRE([AC_PROG_CC])dnl
Packit 709fb3
if test "$ac_prog_cc_stdc" != no; then
Packit 709fb3
  AC_DEFINE(PROTOTYPES, 1,
Packit 709fb3
	    [Define to 1 if the C compiler supports function prototypes.])
Packit 709fb3
  AC_DEFINE(__PROTOTYPES, 1,
Packit 709fb3
	    [Define like PROTOTYPES; this can be used by system headers.])
Packit 709fb3
fi
Packit 709fb3
])# AC_C_PROTOTYPES
Packit 709fb3
Packit 709fb3
Packit 709fb3
# _AC_CXX_STD_TRY(STANDARD, TEST-PROLOGUE, TEST-BODY, OPTION-LIST,
Packit 709fb3
#		  ACTION-IF-AVAILABLE, ACTION-IF-UNAVAILABLE)
Packit 709fb3
# ----------------------------------------------------------------
Packit 709fb3
# Check whether the C++ compiler accepts features of STANDARD (e.g
Packit 709fb3
# `cxx98', `cxx11') by trying to compile a program of TEST-PROLOGUE
Packit 709fb3
# and TEST-BODY.  If this fails, try again with each compiler option
Packit 709fb3
# in the space-separated OPTION-LIST; if one helps, append it to CXX.
Packit 709fb3
# If eventually successful, run ACTION-IF-AVAILABLE, else
Packit 709fb3
# ACTION-IF-UNAVAILABLE.
Packit 709fb3
AC_DEFUN([_AC_CXX_STD_TRY],
Packit 709fb3
[AC_MSG_CHECKING([for $CXX option to enable ]m4_translit(m4_translit($1, [x], [+]), [a-z], [A-Z])[ features])
Packit 709fb3
AC_LANG_PUSH(C++)dnl
Packit 709fb3
AC_CACHE_VAL(ac_cv_prog_cxx_$1,
Packit 709fb3
[ac_cv_prog_cxx_$1=no
Packit 709fb3
ac_save_CXX=$CXX
Packit 709fb3
AC_LANG_CONFTEST([AC_LANG_PROGRAM([$2], [$3])])
Packit 709fb3
for ac_arg in '' $4
Packit 709fb3
do
Packit 709fb3
  CXX="$ac_save_CXX $ac_arg"
Packit 709fb3
  _AC_COMPILE_IFELSE([], [ac_cv_prog_cxx_$1=$ac_arg])
Packit 709fb3
  test "x$ac_cv_prog_cxx_$1" != "xno" && break
Packit 709fb3
done
Packit 709fb3
rm -f conftest.$ac_ext
Packit 709fb3
CXX=$ac_save_CXX
Packit 709fb3
])# AC_CACHE_VAL
Packit 709fb3
ac_prog_cxx_stdcxx_options=
Packit 709fb3
case "x$ac_cv_prog_cxx_$1" in
Packit 709fb3
  x)
Packit 709fb3
    AC_MSG_RESULT([none needed]) ;;
Packit 709fb3
  xno)
Packit 709fb3
    AC_MSG_RESULT([unsupported]) ;;
Packit 709fb3
  *)
Packit 709fb3
    ac_prog_cxx_stdcxx_options=" $ac_cv_prog_cxx_$1"
Packit 709fb3
    CXX=$CXX$ac_prog_cxx_stdcxx_options
Packit 709fb3
    AC_MSG_RESULT([$ac_cv_prog_cxx_$1]) ;;
Packit 709fb3
esac
Packit 709fb3
AC_LANG_POP(C++)dnl
Packit 709fb3
AS_IF([test "x$ac_cv_prog_cxx_$1" != xno], [$5], [$6])
Packit 709fb3
])# _AC_CXX_STD_TRY
Packit 709fb3
Packit 709fb3
# _AC_CXX_CXX98_TEST_HEADER
Packit 709fb3
# -------------------------
Packit 709fb3
# A C++ header suitable for testing for CXX98.
Packit 709fb3
AC_DEFUN([_AC_CXX_CXX98_TEST_HEADER],
Packit 709fb3
[[
Packit 709fb3
#include <algorithm>
Packit 709fb3
#include <cstdlib>
Packit 709fb3
#include <fstream>
Packit 709fb3
#include <iomanip>
Packit 709fb3
#include <iostream>
Packit 709fb3
#include <list>
Packit 709fb3
#include <map>
Packit 709fb3
#include <set>
Packit 709fb3
#include <sstream>
Packit 709fb3
#include <stdexcept>
Packit 709fb3
#include <string>
Packit 709fb3
#include <utility>
Packit 709fb3
#include <vector>
Packit 709fb3
Packit 709fb3
namespace test {
Packit 709fb3
  typedef std::vector<std::string> string_vec;
Packit 709fb3
  typedef std::pair<int,bool> map_value;
Packit 709fb3
  typedef std::map<std::string,map_value> map_type;
Packit 709fb3
  typedef std::set<int> set_type;
Packit 709fb3
Packit 709fb3
  template<typename T>
Packit 709fb3
  class printer {
Packit 709fb3
  public:
Packit 709fb3
    printer(std::ostringstream& os): os(os) {}
Packit 709fb3
    void operator() (T elem) { os << elem << std::endl; }
Packit 709fb3
  private:
Packit 709fb3
    std::ostringstream& os;
Packit 709fb3
  };
Packit 709fb3
}
Packit 709fb3
]])# _AC_CXX_CXX98_TEST_HEADER
Packit 709fb3
Packit 709fb3
# _AC_CXX_CXX98_TEST_BODY
Packit 709fb3
# -----------------------
Packit 709fb3
# A C++ body suitable for testing for CXX98, assuming the corresponding header.
Packit 709fb3
AC_DEFUN([_AC_CXX_CXX98_TEST_BODY],
Packit 709fb3
[[
Packit 709fb3
Packit 709fb3
try {
Packit 709fb3
  // Basic string.
Packit 709fb3
  std::string teststr("ASCII text");
Packit 709fb3
  teststr += " string";
Packit 709fb3
Packit 709fb3
  // Simple vector.
Packit 709fb3
  test::string_vec testvec;
Packit 709fb3
  testvec.push_back(teststr);
Packit 709fb3
  testvec.push_back("foo");
Packit 709fb3
  testvec.push_back("bar");
Packit 709fb3
  if (testvec.size() != 3) {
Packit 709fb3
    throw std::runtime_error("vector size is not 1");
Packit 709fb3
  }
Packit 709fb3
Packit 709fb3
  // Dump vector into stringstream and obtain string.
Packit 709fb3
  std::ostringstream os;
Packit 709fb3
  for (test::string_vec::const_iterator i = testvec.begin();
Packit 709fb3
       i != testvec.end(); ++i) {
Packit 709fb3
    if (i + 1 != testvec.end()) {
Packit 709fb3
      os << teststr << '\n';
Packit 709fb3
    }
Packit 709fb3
  }
Packit 709fb3
  // Check algorithms work.
Packit 709fb3
  std::for_each(testvec.begin(), testvec.end(), test::printer<std::string>(os));
Packit 709fb3
  std::string os_out = os.str();
Packit 709fb3
Packit 709fb3
  // Test pair and map.
Packit 709fb3
  test::map_type testmap;
Packit 709fb3
  testmap.insert(std::make_pair(std::string("key"),
Packit 709fb3
                                std::make_pair(53,false)));
Packit 709fb3
Packit 709fb3
  // Test set.
Packit 709fb3
  int values[] = {9, 7, 13, 15, 4, 18, 12, 10, 5, 3, 14, 19, 17, 8, 6, 20, 16, 2, 11, 1};
Packit 709fb3
  test::set_type testset(values, values + sizeof(values)/sizeof(values[0]));
Packit 709fb3
  std::list<int> testlist(testset.begin(), testset.end());
Packit 709fb3
  std::copy(testset.begin(), testset.end(), std::back_inserter(testlist));
Packit 709fb3
} catch (const std::exception& e) {
Packit 709fb3
  std::cerr << "Caught exception: " << e.what() << std::endl;
Packit 709fb3
Packit 709fb3
  // Test fstream
Packit 709fb3
  std::ofstream of("test.txt");
Packit 709fb3
  of << "Test ASCII text\n" << std::flush;
Packit 709fb3
  of << "N= " << std::hex << std::setw(8) << std::left << 534 << std::endl;
Packit 709fb3
  of.close();
Packit 709fb3
}
Packit 709fb3
std::exit(0);
Packit 709fb3
]])
Packit 709fb3
Packit 709fb3
# _AC_CXX_CXX11_TEST_HEADER
Packit 709fb3
# -------------------------
Packit 709fb3
# A C++ header suitable for testing for CXX11.
Packit 709fb3
AC_DEFUN([_AC_CXX_CXX11_TEST_HEADER],
Packit 709fb3
[[
Packit 709fb3
#include <deque>
Packit 709fb3
#include <functional>
Packit 709fb3
#include <memory>
Packit 709fb3
#include <tuple>
Packit 709fb3
#include <array>
Packit 709fb3
#include <regex>
Packit 709fb3
#include <iostream>
Packit 709fb3
Packit 709fb3
namespace cxx11test
Packit 709fb3
{
Packit 709fb3
  typedef std::shared_ptr<std::string> sptr;
Packit 709fb3
  typedef std::weak_ptr<std::string> wptr;
Packit 709fb3
Packit 709fb3
  typedef std::tuple<std::string,int,double> tp;
Packit 709fb3
  typedef std::array<int, 20> int_array;
Packit 709fb3
Packit 709fb3
  constexpr int get_val() { return 20; }
Packit 709fb3
Packit 709fb3
  struct testinit
Packit 709fb3
  {
Packit 709fb3
    int i;
Packit 709fb3
    double d;
Packit 709fb3
  };
Packit 709fb3
Packit 709fb3
  class delegate  {
Packit 709fb3
  public:
Packit 709fb3
    delegate(int n) : n(n) {}
Packit 709fb3
    delegate(): delegate(2354) {}
Packit 709fb3
Packit 709fb3
    virtual int getval() { return this->n; };
Packit 709fb3
  protected:
Packit 709fb3
    int n;
Packit 709fb3
  };
Packit 709fb3
Packit 709fb3
  class overridden : public delegate {
Packit 709fb3
  public:
Packit 709fb3
    overridden(int n): delegate(n) {}
Packit 709fb3
    virtual int getval() override final { return this->n * 2; }
Packit 709fb3
  };
Packit 709fb3
Packit 709fb3
  class nocopy {
Packit 709fb3
  public:
Packit 709fb3
    nocopy(int i): i(i) {}
Packit 709fb3
    nocopy() = default;
Packit 709fb3
    nocopy(const nocopy&) = delete;
Packit 709fb3
    nocopy & operator=(const nocopy&) = delete;
Packit 709fb3
  private:
Packit 709fb3
    int i;
Packit 709fb3
  };
Packit 709fb3
}
Packit 709fb3
]])# _AC_CXX_CXX11_TEST_HEADER
Packit 709fb3
Packit 709fb3
# _AC_CXX_CXX11_TEST_BODY
Packit 709fb3
# -----------------------
Packit 709fb3
# A C++ body suitable for testing for CXX11, assuming the corresponding header.
Packit 709fb3
AC_DEFUN([_AC_CXX_CXX11_TEST_BODY],
Packit 709fb3
[[
Packit 709fb3
{
Packit 709fb3
  // Test auto and decltype
Packit 709fb3
  std::deque<int> d;
Packit 709fb3
  d.push_front(43);
Packit 709fb3
  d.push_front(484);
Packit 709fb3
  d.push_front(3);
Packit 709fb3
  d.push_front(844);
Packit 709fb3
  int total = 0;
Packit 709fb3
  for (auto i = d.begin(); i != d.end(); ++i) { total += *i; }
Packit 709fb3
Packit 709fb3
  auto a1 = 6538;
Packit 709fb3
  auto a2 = 48573953.4;
Packit 709fb3
  auto a3 = "String literal";
Packit 709fb3
Packit 709fb3
  decltype(a2) a4 = 34895.034;
Packit 709fb3
}
Packit 709fb3
{
Packit 709fb3
  // Test constexpr
Packit 709fb3
  short sa[cxx11test::get_val()] = { 0 };
Packit 709fb3
}
Packit 709fb3
{
Packit 709fb3
  // Test initializer lists
Packit 709fb3
  cxx11test::testinit il = { 4323, 435234.23544 };
Packit 709fb3
}
Packit 709fb3
{
Packit 709fb3
  // Test range-based for and lambda
Packit 709fb3
  cxx11test::int_array array = {9, 7, 13, 15, 4, 18, 12, 10, 5, 3, 14, 19, 17, 8, 6, 20, 16, 2, 11, 1};
Packit 709fb3
  for (int &x : array) { x += 23; }
Packit 709fb3
  std::for_each(array.begin(), array.end(), [](int v1){ std::cout << v1; });
Packit 709fb3
}
Packit 709fb3
{
Packit 709fb3
  using cxx11test::sptr;
Packit 709fb3
  using cxx11test::wptr;
Packit 709fb3
Packit 709fb3
  sptr sp(new std::string("ASCII string"));
Packit 709fb3
  wptr wp(sp);
Packit 709fb3
  sptr sp2(wp);
Packit 709fb3
}
Packit 709fb3
{
Packit 709fb3
  cxx11test::tp tuple("test", 54, 45.53434);
Packit 709fb3
  double d = std::get<2>(tuple);
Packit 709fb3
  std::string s;
Packit 709fb3
  int i;
Packit 709fb3
  std::tie(s,i,d) = tuple;
Packit 709fb3
}
Packit 709fb3
{
Packit 709fb3
  static std::regex filename_regex("^_?([a-z0-9_.]+-)+[a-z0-9]+$");
Packit 709fb3
  std::string testmatch("Test if this string matches");
Packit 709fb3
  bool match = std::regex_search(testmatch, filename_regex);
Packit 709fb3
}
Packit 709fb3
{
Packit 709fb3
  cxx11test::int_array array = {9, 7, 13, 15, 4, 18, 12, 10, 5, 3, 14, 19, 17, 8, 6, 20, 16, 2, 11, 1};
Packit 709fb3
  cxx11test::int_array::size_type size = array.size();
Packit 709fb3
}
Packit 709fb3
{
Packit 709fb3
  // Test constructor delegation
Packit 709fb3
  cxx11test::delegate d1;
Packit 709fb3
  cxx11test::delegate d2();
Packit 709fb3
  cxx11test::delegate d3(45);
Packit 709fb3
}
Packit 709fb3
{
Packit 709fb3
  // Test override and final
Packit 709fb3
  cxx11test::overridden o1(55464);
Packit 709fb3
}
Packit 709fb3
{
Packit 709fb3
  // Test nullptr
Packit 709fb3
  char *c = nullptr;
Packit 709fb3
}
Packit 709fb3
{
Packit 709fb3
  // Test template brackets
Packit 709fb3
  std::vector<std::pair<int,char*>> v1;
Packit 709fb3
}
Packit 709fb3
{
Packit 709fb3
  // Unicode literals
Packit 709fb3
  char const *utf8 = u8"UTF-8 string \u2500";
Packit 709fb3
  char16_t const *utf16 = u"UTF-8 string \u2500";
Packit 709fb3
  char32_t const *utf32 = U"UTF-32 string \u2500";
Packit 709fb3
}
Packit 709fb3
]])
Packit 709fb3
Packit 709fb3
# _AC_PROG_CXX_CXX98 ([ACTION-IF-AVAILABLE], [ACTION-IF-UNAVAILABLE])
Packit 709fb3
# -------------------------------------------------------------------
Packit 709fb3
Packit 709fb3
# If the C++ compiler is not in ISO C++98 mode by default, try to add
Packit 709fb3
# an option to output variable CXX to make it so.  This macro tries
Packit 709fb3
# various options that select ISO C++98 on some system or another.  It
Packit 709fb3
# considers the compiler to be in ISO C++98 mode if it handles basic
Packit 709fb3
# features of the std namespace including: string, containers (list,
Packit 709fb3
# map, set, vector), streams (fstreams, iostreams, stringstreams,
Packit 709fb3
# iomanip), pair, exceptions and algorithms.
Packit 709fb3
Packit 709fb3
Packit 709fb3
AC_DEFUN([_AC_PROG_CXX_CXX98],
Packit 709fb3
[_AC_CXX_STD_TRY([cxx98],
Packit 709fb3
[_AC_CXX_CXX98_TEST_HEADER],
Packit 709fb3
[_AC_CXX_CXX98_TEST_BODY],
Packit 709fb3
dnl Try
Packit 709fb3
dnl GCC		-std=gnu++98 (unused restrictive mode: -std=c++98)
Packit 709fb3
dnl IBM XL C	-qlanglvl=extended
Packit 709fb3
dnl HP aC++	-AA
Packit 709fb3
dnl Intel ICC	-std=gnu++98
Packit 709fb3
dnl Solaris	N/A (default)
Packit 709fb3
dnl Tru64	N/A (default, but -std gnu could be used)
Packit 709fb3
dnl with extended modes being tried first.
Packit 709fb3
[[-std=gnu++98 -std=c++98 -qlanglvl=extended -AA]], [$1], [$2])[]dnl
Packit 709fb3
])# _AC_PROG_CXX_CXX98
Packit 709fb3
Packit 709fb3
# _AC_PROG_CXX_CXX11 ([ACTION-IF-AVAILABLE], [ACTION-IF-UNAVAILABLE])
Packit 709fb3
# -------------------------------------------------------------------
Packit 709fb3
# If the C++ compiler is not in ISO CXX11 mode by default, try to add
Packit 709fb3
# an option to output variable CXX to make it so.  This macro tries
Packit 709fb3
# various options that select ISO C++11 on some system or another.  It
Packit 709fb3
# considers the compiler to be in ISO C++11 mode if it handles all the
Packit 709fb3
# tests from the C++98 checks, plus the following: Language features
Packit 709fb3
# (auto, constexpr, decltype, default/deleted constructors, delegate
Packit 709fb3
# constructors, final, initializer lists, lambda functions, nullptr,
Packit 709fb3
# override, range-based for loops, template brackets without spaces,
Packit 709fb3
# unicode literals) and library features (array, memory (shared_ptr,
Packit 709fb3
# weak_ptr), regex and tuple types).
Packit 709fb3
AC_DEFUN([_AC_PROG_CXX_CXX11],
Packit 709fb3
[_AC_CXX_STD_TRY([cxx11],
Packit 709fb3
[_AC_CXX_CXX11_TEST_HEADER
Packit 709fb3
_AC_CXX_CXX98_TEST_HEADER],
Packit 709fb3
[_AC_CXX_CXX11_TEST_BODY
Packit 709fb3
_AC_CXX_CXX98_TEST_BODY],
Packit 709fb3
dnl Try
Packit 709fb3
dnl GCC		-std=gnu++11 (unused restrictive mode: -std=c++11) [and 0x variants]
Packit 709fb3
dnl IBM XL C	-qlanglvl=extended0x
Packit 709fb3
dnl		(pre-V12.1; unused restrictive mode: -qlanglvl=stdcxx11)
Packit 709fb3
dnl HP aC++	-AA
Packit 709fb3
dnl Intel ICC	-std=c++11 -std=c++0x
Packit 709fb3
dnl Solaris	N/A (no support)
Packit 709fb3
dnl Tru64	N/A (no support)
Packit 709fb3
dnl with extended modes being tried first.
Packit 709fb3
[[-std=gnu++11 -std=c++11 -std=gnu++0x -std=c++0x -qlanglvl=extended0x -AA]], [$1], [$2])[]dnl
Packit 709fb3
])# _AC_PROG_CXX_CXX11