1 # ============================================================================
2 # http://www.gnu.org/software/autoconf-archive/ax_cxx_compile_stdcxx_11.html
3 # ============================================================================
7 # AX_CXX_COMPILE_STDCXX_11([ext|noext],[mandatory|optional])
11 # Check for baseline language coverage in the compiler for the C++11
12 # standard; if necessary, add switches to CXXFLAGS to enable support.
14 # The first argument, if specified, indicates whether you insist on an
15 # extended mode (e.g. -std=gnu++11) or a strict conformance mode (e.g.
16 # -std=c++11). If neither is specified, you get whatever works, with
17 # preference for an extended mode.
19 # The second argument, if specified 'mandatory' or if left unspecified,
20 # indicates that baseline C++11 support is required and that the macro
21 # should error out if no mode with that support is found. If specified
22 # 'optional', then configuration proceeds regardless, after defining
23 # HAVE_CXX11 if and only if a supporting mode is found.
27 # Copyright (c) 2008 Benjamin Kosnik <bkoz@redhat.com>
28 # Copyright (c) 2012 Zack Weinberg <zackw@panix.com>
29 # Copyright (c) 2013 Roy Stogner <roystgnr@ices.utexas.edu>
30 # Copyright (c) 2014, 2015 Google Inc.; contributed by Alexey Sokolov <sokolov@google.com>
32 # Copying and distribution of this file, with or without modification, are
33 # permitted in any medium without royalty provided the copyright notice
34 # and this notice are preserved. This file is offered as-is, without any
39 m4_define([_AX_CXX_COMPILE_STDCXX_11_testbody], [[
43 static_assert(sizeof(int) <= sizeof(T), "not big enough");
49 struct Child : public Base {
50 virtual void f() override {}
53 typedef check<check<bool>> right_angle_brackets;
58 typedef check<int> check_type;
60 check_type&& cr = static_cast<check_type&&>(c);
64 // Prevent Clang error: unused variable 'l' [-Werror,-Wunused-variable]
65 struct use_l { use_l() { l(); } };
67 // http://stackoverflow.com/questions/13728184/template-aliases-and-sfinae
68 // Clang 3.1 fails with headers of libstd++ 4.8.3 when using std::function because of this
69 namespace test_template_alias_sfinae {
73 using member = typename T::member_type;
79 void func(member<T>*) {}
89 AC_DEFUN([AX_CXX_COMPILE_STDCXX_11], [dnl
93 [m4_fatal([invalid argument `$1' to AX_CXX_COMPILE_STDCXX_11])])dnl
94 m4_if([$2], [], [ax_cxx_compile_cxx11_required=true],
95 [$2], [mandatory], [ax_cxx_compile_cxx11_required=true],
96 [$2], [optional], [ax_cxx_compile_cxx11_required=false],
97 [m4_fatal([invalid second argument `$2' to AX_CXX_COMPILE_STDCXX_11])])
98 AC_LANG_PUSH([C++])dnl
100 AC_CACHE_CHECK(whether $CXX supports C++11 features by default,
101 ax_cv_cxx_compile_cxx11,
102 [AC_COMPILE_IFELSE([AC_LANG_SOURCE([_AX_CXX_COMPILE_STDCXX_11_testbody])],
103 [ax_cv_cxx_compile_cxx11=yes],
104 [ax_cv_cxx_compile_cxx11=no])])
105 if test x$ax_cv_cxx_compile_cxx11 = xyes; then
109 m4_if([$1], [noext], [], [dnl
110 if test x$ac_success = xno; then
111 for switch in -std=gnu++11 -std=gnu++0x; do
112 cachevar=AS_TR_SH([ax_cv_cxx_compile_cxx11_$switch])
113 AC_CACHE_CHECK(whether $CXX supports C++11 features with $switch,
115 [ac_save_CXXFLAGS="$CXXFLAGS"
116 CXXFLAGS="$CXXFLAGS $switch"
117 AC_COMPILE_IFELSE([AC_LANG_SOURCE([_AX_CXX_COMPILE_STDCXX_11_testbody])],
118 [eval $cachevar=yes],
120 CXXFLAGS="$ac_save_CXXFLAGS"])
121 if eval test x\$$cachevar = xyes; then
122 CXXFLAGS="$CXXFLAGS $switch"
129 m4_if([$1], [ext], [], [dnl
130 if test x$ac_success = xno; then
131 dnl HP's aCC needs +std=c++11 according to:
132 dnl http://h21007.www2.hp.com/portal/download/files/unprot/aCxx/PDF_Release_Notes/769149-001.pdf
133 for switch in -std=c++11 -std=c++0x +std=c++11; do
134 cachevar=AS_TR_SH([ax_cv_cxx_compile_cxx11_$switch])
135 AC_CACHE_CHECK(whether $CXX supports C++11 features with $switch,
137 [ac_save_CXXFLAGS="$CXXFLAGS"
138 CXXFLAGS="$CXXFLAGS $switch"
139 AC_COMPILE_IFELSE([AC_LANG_SOURCE([_AX_CXX_COMPILE_STDCXX_11_testbody])],
140 [eval $cachevar=yes],
142 CXXFLAGS="$ac_save_CXXFLAGS"])
143 if eval test x\$$cachevar = xyes; then
144 CXXFLAGS="$CXXFLAGS $switch"
151 if test x$ax_cxx_compile_cxx11_required = xtrue; then
152 if test x$ac_success = xno; then
153 AC_MSG_ERROR([*** A compiler with support for C++11 language features is required.])
156 if test x$ac_success = xno; then
158 AC_MSG_NOTICE([No compiler with C++11 support was found])
161 AC_DEFINE(HAVE_CXX11,1,
162 [define if the compiler supports basic C++11 syntax])