1 ## Copyright (C) 1996-2019 The Squid Software Foundation and contributors
3 ## Squid software is distributed under GPLv2+ license and includes
4 ## contributions from numerous individuals and organizations.
5 ## Please see the COPYING and CONTRIBUTORS files for details.
8 # ============================================================================
9 # http://www.gnu.org/software/autoconf-archive/ax_cxx_compile_stdcxx_11.html
10 # ============================================================================
14 # AX_CXX_COMPILE_STDCXX_11([ext|noext],[mandatory|optional])
18 # Check for baseline language coverage in the compiler for the C++11
19 # standard; if necessary, add switches to CXXFLAGS to enable support.
21 # The first argument, if specified, indicates whether you insist on an
22 # extended mode (e.g. -std=gnu++11) or a strict conformance mode (e.g.
23 # -std=c++11). If neither is specified, you get whatever works, with
24 # preference for an extended mode.
26 # The second argument, if specified 'mandatory' or if left unspecified,
27 # indicates that baseline C++11 support is required and that the macro
28 # should error out if no mode with that support is found. If specified
29 # 'optional', then configuration proceeds regardless, after defining
30 # HAVE_CXX11 if and only if a supporting mode is found.
34 # Copyright (c) 2008 Benjamin Kosnik <bkoz@redhat.com>
35 # Copyright (c) 2012 Zack Weinberg <zackw@panix.com>
36 # Copyright (c) 2013 Roy Stogner <roystgnr@ices.utexas.edu>
37 # Copyright (c) 2014 Alexey Sokolov <sokolov@google.com>
39 # Copying and distribution of this file, with or without modification, are
40 # permitted in any medium without royalty provided the copyright notice
41 # and this notice are preserved. This file is offered as-is, without any
46 m4_define([_AX_CXX_COMPILE_STDCXX_11_testbody], [[
50 static_assert(sizeof(int) <= sizeof(T), "not big enough"); // GCC 4.3+
53 #if WHEN_SQUID_HAS_MANDATORY_GCC_4_789_SUPPORT
57 struct Child : public Base {
58 virtual void f() override {} // GCC 4.7+
62 typedef check<check<bool>> right_angle_brackets; // GCC 4.3+
65 decltype(a) b; // GCC 4.3+
67 typedef check<int> check_type;
69 check_type&& cr = static_cast<check_type&&>(c); // GCC 4.3+
71 auto d = a; // GCC 4.4+
72 #if WHEN_SQUID_HAS_MANDATORY_GCC_4_789_SUPPORT
73 auto l = [](){}; // GCC 4.5+ (void lambda seems not to be documented)
77 AC_DEFUN([AX_CXX_COMPILE_STDCXX_11], [dnl
81 [m4_fatal([invalid argument `$1' to AX_CXX_COMPILE_STDCXX_11])])dnl
82 m4_if([$2], [], [ax_cxx_compile_cxx11_required=true],
83 [$2], [mandatory], [ax_cxx_compile_cxx11_required=true],
84 [$2], [optional], [ax_cxx_compile_cxx11_required=false],
85 [m4_fatal([invalid second argument `$2' to AX_CXX_COMPILE_STDCXX_11])])
86 AC_LANG_PUSH([C++])dnl
88 AC_CACHE_CHECK(whether $CXX supports C++11 features by default,
89 ax_cv_cxx_compile_cxx11,
90 [AC_COMPILE_IFELSE([AC_LANG_SOURCE([_AX_CXX_COMPILE_STDCXX_11_testbody])],
91 [ax_cv_cxx_compile_cxx11=yes],
92 [ax_cv_cxx_compile_cxx11=no])])
93 if test x$ax_cv_cxx_compile_cxx11 = xyes; then
97 m4_if([$1], [noext], [], [dnl
98 if test x$ac_success = xno; then
99 for switch in -std=gnu++11 -std=gnu++0x; do
100 cachevar=AS_TR_SH([ax_cv_cxx_compile_cxx11_$switch])
101 AC_CACHE_CHECK(whether $CXX supports C++11 features with $switch,
103 [ac_save_CXXFLAGS="$CXXFLAGS"
104 CXXFLAGS="$CXXFLAGS $switch"
105 AC_COMPILE_IFELSE([AC_LANG_SOURCE([_AX_CXX_COMPILE_STDCXX_11_testbody])],
106 [eval $cachevar=yes],
108 CXXFLAGS="$ac_save_CXXFLAGS"])
109 if eval test x\$$cachevar = xyes; then
110 CXXFLAGS="$CXXFLAGS $switch"
117 m4_if([$1], [ext], [], [dnl
118 if test x$ac_success = xno; then
119 for switch in -std=c++11 -std=c++0x; do
120 cachevar=AS_TR_SH([ax_cv_cxx_compile_cxx11_$switch])
121 AC_CACHE_CHECK(whether $CXX supports C++11 features with $switch,
123 [ac_save_CXXFLAGS="$CXXFLAGS"
124 CXXFLAGS="$CXXFLAGS $switch"
125 AC_COMPILE_IFELSE([AC_LANG_SOURCE([_AX_CXX_COMPILE_STDCXX_11_testbody])],
126 [eval $cachevar=yes],
128 CXXFLAGS="$ac_save_CXXFLAGS"])
129 if eval test x\$$cachevar = xyes; then
130 CXXFLAGS="$CXXFLAGS $switch"
137 if test x$ax_cxx_compile_cxx11_required = xtrue; then
138 if test x$ac_success = xno; then
139 AC_MSG_ERROR([*** A compiler with support for C++11 language features is required.])
142 if test x$ac_success = xno; then
144 AC_MSG_NOTICE([No compiler with C++11 support was found])
147 AC_DEFINE(HAVE_CXX11,1,
148 [define if the compiler supports basic C++11 syntax])