1# ============================================================================ 2# http://www.gnu.org/software/autoconf-archive/ax_cxx_compile_stdcxx_11.html 3# ============================================================================ 4# 5# SYNOPSIS 6# 7# AX_CXX_COMPILE_STDCXX_11([ext|noext],[mandatory|optional]) 8# 9# DESCRIPTION 10# 11# Check for baseline language coverage in the compiler for the C++11 12# standard; if necessary, add switches to CXXFLAGS to enable support. 13# 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. 18# 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. 24# 25# LICENSE 26# 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> 31# Copyright (c) 2015 Paul Norman <penorman@mac.com> 32# 33# Copying and distribution of this file, with or without modification, are 34# permitted in any medium without royalty provided the copyright notice 35# and this notice are preserved. This file is offered as-is, without any 36# warranty. 37 38#serial 13 39 40m4_define([_AX_CXX_COMPILE_STDCXX_11_testbody], [[ 41 template <typename T> 42 struct check 43 { 44 static_assert(sizeof(int) <= sizeof(T), "not big enough"); 45 }; 46 47 struct Base { 48 virtual void f() {} 49 }; 50 struct Child : public Base { 51 virtual void f() override {} 52 }; 53 54 typedef check<check<bool>> right_angle_brackets; 55 56 int a; 57 decltype(a) b; 58 59 typedef check<int> check_type; 60 check_type c; 61 check_type&& cr = static_cast<check_type&&>(c); 62 63 auto d = a; 64 auto l = [](){}; 65 // Prevent Clang error: unused variable 'l' [-Werror,-Wunused-variable] 66 struct use_l { use_l() { l(); } }; 67 68 // http://stackoverflow.com/questions/13728184/template-aliases-and-sfinae 69 // Clang 3.1 fails with headers of libstd++ 4.8.3 when using std::function because of this 70 namespace test_template_alias_sfinae { 71 struct foo {}; 72 73 template<typename T> 74 using member = typename T::member_type; 75 76 template<typename T> 77 void func(...) {} 78 79 template<typename T> 80 void func(member<T>*) {} 81 82 void test(); 83 84 void test() { 85 func<foo>(0); 86 } 87 } 88 89 // Check for C++11 attribute support 90 void noret [[noreturn]] () { throw 0; } 91]]) 92 93AC_DEFUN([AX_CXX_COMPILE_STDCXX_11], [dnl 94 m4_if([$1], [], [], 95 [$1], [ext], [], 96 [$1], [noext], [], 97 [m4_fatal([invalid argument `$1' to AX_CXX_COMPILE_STDCXX_11])])dnl 98 m4_if([$2], [], [ax_cxx_compile_cxx11_required=true], 99 [$2], [mandatory], [ax_cxx_compile_cxx11_required=true], 100 [$2], [optional], [ax_cxx_compile_cxx11_required=false], 101 [m4_fatal([invalid second argument `$2' to AX_CXX_COMPILE_STDCXX_11])]) 102 AC_LANG_PUSH([C++])dnl 103 ac_success=no 104 AC_CACHE_CHECK(whether $CXX supports C++11 features by default, 105 ax_cv_cxx_compile_cxx11, 106 [AC_COMPILE_IFELSE([AC_LANG_SOURCE([_AX_CXX_COMPILE_STDCXX_11_testbody])], 107 [ax_cv_cxx_compile_cxx11=yes], 108 [ax_cv_cxx_compile_cxx11=no])]) 109 if test x$ax_cv_cxx_compile_cxx11 = xyes; then 110 ac_success=yes 111 fi 112 113 m4_if([$1], [noext], [], [dnl 114 if test x$ac_success = xno; then 115 for switch in -std=gnu++11 -std=gnu++0x; do 116 cachevar=AS_TR_SH([ax_cv_cxx_compile_cxx11_$switch]) 117 AC_CACHE_CHECK(whether $CXX supports C++11 features with $switch, 118 $cachevar, 119 [ac_save_CXXFLAGS="$CXXFLAGS" 120 CXXFLAGS="$CXXFLAGS $switch" 121 AC_COMPILE_IFELSE([AC_LANG_SOURCE([_AX_CXX_COMPILE_STDCXX_11_testbody])], 122 [eval $cachevar=yes], 123 [eval $cachevar=no]) 124 CXXFLAGS="$ac_save_CXXFLAGS"]) 125 if eval test x\$$cachevar = xyes; then 126 CXXFLAGS="$CXXFLAGS $switch" 127 ac_success=yes 128 break 129 fi 130 done 131 fi]) 132 133 m4_if([$1], [ext], [], [dnl 134 if test x$ac_success = xno; then 135 dnl HP's aCC needs +std=c++11 according to: 136 dnl http://h21007.www2.hp.com/portal/download/files/unprot/aCxx/PDF_Release_Notes/769149-001.pdf 137 dnl Cray's crayCC needs "-h std=c++11" 138 for switch in -std=c++11 -std=c++0x +std=c++11 "-h std=c++11"; do 139 cachevar=AS_TR_SH([ax_cv_cxx_compile_cxx11_$switch]) 140 AC_CACHE_CHECK(whether $CXX supports C++11 features with $switch, 141 $cachevar, 142 [ac_save_CXXFLAGS="$CXXFLAGS" 143 CXXFLAGS="$CXXFLAGS $switch" 144 AC_COMPILE_IFELSE([AC_LANG_SOURCE([_AX_CXX_COMPILE_STDCXX_11_testbody])], 145 [eval $cachevar=yes], 146 [eval $cachevar=no]) 147 CXXFLAGS="$ac_save_CXXFLAGS"]) 148 if eval test x\$$cachevar = xyes; then 149 CXXFLAGS="$CXXFLAGS $switch" 150 ac_success=yes 151 break 152 fi 153 done 154 fi]) 155 AC_LANG_POP([C++]) 156 if test x$ax_cxx_compile_cxx11_required = xtrue; then 157 if test x$ac_success = xno; then 158 AC_MSG_ERROR([*** A compiler with support for C++11 language features is required.]) 159 fi 160 else 161 if test x$ac_success = xno; then 162 HAVE_CXX11=0 163 AC_MSG_NOTICE([No compiler with C++11 support was found]) 164 else 165 HAVE_CXX11=1 166 AC_DEFINE(HAVE_CXX11,1, 167 [define if the compiler supports basic C++11 syntax]) 168 fi 169 170 AC_SUBST(HAVE_CXX11) 171 fi 172]) 173