]> git.ipfire.org Git - thirdparty/squid.git/blob - acinclude/ax_cxx_compile_stdcxx_11.m4
Boilerplate: update acinclude/ and configure.ac copyrights
[thirdparty/squid.git] / acinclude / ax_cxx_compile_stdcxx_11.m4
1 ## Copyright (C) 1996-2014 The Squid Software Foundation and contributors
2 ##
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.
6 ##
7
8 # ============================================================================
9 # http://www.gnu.org/software/autoconf-archive/ax_cxx_compile_stdcxx_11.html
10 # ============================================================================
11 #
12 # SYNOPSIS
13 #
14 # AX_CXX_COMPILE_STDCXX_11([ext|noext],[mandatory|optional])
15 #
16 # DESCRIPTION
17 #
18 # Check for baseline language coverage in the compiler for the C++11
19 # standard; if necessary, add switches to CXXFLAGS to enable support.
20 #
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.
25 #
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.
31 #
32 # LICENSE
33 #
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>
38 #
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
42 # warranty.
43
44 #serial 4
45
46 m4_define([_AX_CXX_COMPILE_STDCXX_11_testbody], [[
47 template <typename T>
48 struct check
49 {
50 static_assert(sizeof(int) <= sizeof(T), "not big enough");
51 };
52
53 struct Base {
54 virtual void f() {}
55 };
56 struct Child : public Base {
57 virtual void f() override {}
58 };
59
60 typedef check<check<bool>> right_angle_brackets;
61
62 int a;
63 decltype(a) b;
64
65 typedef check<int> check_type;
66 check_type c;
67 check_type&& cr = static_cast<check_type&&>(c);
68
69 auto d = a;
70 auto l = [](){};
71 ]])
72
73 AC_DEFUN([AX_CXX_COMPILE_STDCXX_11], [dnl
74 m4_if([$1], [], [],
75 [$1], [ext], [],
76 [$1], [noext], [],
77 [m4_fatal([invalid argument `$1' to AX_CXX_COMPILE_STDCXX_11])])dnl
78 m4_if([$2], [], [ax_cxx_compile_cxx11_required=true],
79 [$2], [mandatory], [ax_cxx_compile_cxx11_required=true],
80 [$2], [optional], [ax_cxx_compile_cxx11_required=false],
81 [m4_fatal([invalid second argument `$2' to AX_CXX_COMPILE_STDCXX_11])])
82 AC_LANG_PUSH([C++])dnl
83 ac_success=no
84 AC_CACHE_CHECK(whether $CXX supports C++11 features by default,
85 ax_cv_cxx_compile_cxx11,
86 [AC_COMPILE_IFELSE([AC_LANG_SOURCE([_AX_CXX_COMPILE_STDCXX_11_testbody])],
87 [ax_cv_cxx_compile_cxx11=yes],
88 [ax_cv_cxx_compile_cxx11=no])])
89 if test x$ax_cv_cxx_compile_cxx11 = xyes; then
90 ac_success=yes
91 fi
92
93 m4_if([$1], [noext], [], [dnl
94 if test x$ac_success = xno; then
95 for switch in -std=gnu++11 -std=gnu++0x; do
96 cachevar=AS_TR_SH([ax_cv_cxx_compile_cxx11_$switch])
97 AC_CACHE_CHECK(whether $CXX supports C++11 features with $switch,
98 $cachevar,
99 [ac_save_CXXFLAGS="$CXXFLAGS"
100 CXXFLAGS="$CXXFLAGS $switch"
101 AC_COMPILE_IFELSE([AC_LANG_SOURCE([_AX_CXX_COMPILE_STDCXX_11_testbody])],
102 [eval $cachevar=yes],
103 [eval $cachevar=no])
104 CXXFLAGS="$ac_save_CXXFLAGS"])
105 if eval test x\$$cachevar = xyes; then
106 CXXFLAGS="$CXXFLAGS $switch"
107 ac_success=yes
108 break
109 fi
110 done
111 fi])
112
113 m4_if([$1], [ext], [], [dnl
114 if test x$ac_success = xno; then
115 for switch in -std=c++11 -std=c++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 AC_LANG_POP([C++])
133 if test x$ax_cxx_compile_cxx11_required = xtrue; then
134 if test x$ac_success = xno; then
135 AC_MSG_ERROR([*** A compiler with support for C++11 language features is required.])
136 fi
137 else
138 if test x$ac_success = xno; then
139 HAVE_CXX11=0
140 AC_MSG_NOTICE([No compiler with C++11 support was found])
141 else
142 HAVE_CXX11=1
143 AC_DEFINE(HAVE_CXX11,1,
144 [define if the compiler supports basic C++11 syntax])
145 fi
146
147 AC_SUBST(HAVE_CXX11)
148 fi
149 ])