Add automated test on delayed return value handling in ExternalInterface.call().
[gnash.git] / macros / ax_cxx_compile_stdcxx_11.m4
blob7fb06eb1ea7222a01cd27f3e43a6ef0cb848447b
1 # ============================================================================
2 #  http://www.gnu.org/software/autoconf-archive/ax_cxx_compile_stdcxx_11.html
3 # ============================================================================
5 # SYNOPSIS
7 #   AX_CXX_COMPILE_STDCXX_11([ext|noext],[mandatory|optional])
9 # DESCRIPTION
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.
25 # LICENSE
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 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
35 #   warranty.
37 #serial 4
39 m4_define([_AX_CXX_COMPILE_STDCXX_11_testbody], [[
40   template <typename T>
41     struct check
42     {
43       static_assert(sizeof(int) <= sizeof(T), "not big enough");
44     };
46 #if 0
47     // The override keyword is not supported until GCC-4.7.
48     struct Base {
49     virtual void f() {}
50     };
51     struct Child : public Base {
52     virtual void f() override {}
53     };
54 #endif
56     typedef check<check<bool>> right_angle_brackets;
58     int a;
59     decltype(a) b;
61     typedef check<int> check_type;
62     check_type c;
63     check_type&& cr = static_cast<check_type&&>(c);
65     auto d = a;
66     auto l = [](){};
67 ]])
69 AC_DEFUN([AX_CXX_COMPILE_STDCXX_11], [dnl
70   m4_if([$1], [], [],
71         [$1], [ext], [],
72         [$1], [noext], [],
73         [m4_fatal([invalid argument `$1' to AX_CXX_COMPILE_STDCXX_11])])dnl
74   m4_if([$2], [], [ax_cxx_compile_cxx11_required=true],
75         [$2], [mandatory], [ax_cxx_compile_cxx11_required=true],
76         [$2], [optional], [ax_cxx_compile_cxx11_required=false],
77         [m4_fatal([invalid second argument `$2' to AX_CXX_COMPILE_STDCXX_11])])
78   AC_LANG_PUSH([C++])dnl
79   ac_success=no
80   AC_CACHE_CHECK(whether $CXX supports C++11 features by default,
81   ax_cv_cxx_compile_cxx11,
82   [AC_COMPILE_IFELSE([AC_LANG_SOURCE([_AX_CXX_COMPILE_STDCXX_11_testbody])],
83     [ax_cv_cxx_compile_cxx11=yes],
84     [ax_cv_cxx_compile_cxx11=no])])
85   if test x$ax_cv_cxx_compile_cxx11 = xyes; then
86     ac_success=yes
87   fi
89   m4_if([$1], [noext], [], [dnl
90   if test x$ac_success = xno; then
91     for switch in -std=gnu++11 -std=gnu++0x; do
92       cachevar=AS_TR_SH([ax_cv_cxx_compile_cxx11_$switch])
93       AC_CACHE_CHECK(whether $CXX supports C++11 features with $switch,
94                      $cachevar,
95         [ac_save_CXXFLAGS="$CXXFLAGS"
96          CXXFLAGS="$CXXFLAGS $switch"
97          AC_COMPILE_IFELSE([AC_LANG_SOURCE([_AX_CXX_COMPILE_STDCXX_11_testbody])],
98           [eval $cachevar=yes],
99           [eval $cachevar=no])
100          CXXFLAGS="$ac_save_CXXFLAGS"])
101       if eval test x\$$cachevar = xyes; then
102         CXXFLAGS="$CXXFLAGS $switch"
103         ac_success=yes
104         break
105       fi
106     done
107   fi])
109   m4_if([$1], [ext], [], [dnl
110   if test x$ac_success = xno; then
111     for switch in -std=c++11 -std=c++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,
114                      $cachevar,
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],
119           [eval $cachevar=no])
120          CXXFLAGS="$ac_save_CXXFLAGS"])
121       if eval test x\$$cachevar = xyes; then
122         CXXFLAGS="$CXXFLAGS $switch"
123         ac_success=yes
124         break
125       fi
126     done
127   fi])
128   AC_LANG_POP([C++])
129   if test x$ax_cxx_compile_cxx11_required = xtrue; then
130     if test x$ac_success = xno; then
131       AC_MSG_ERROR([*** A compiler with support for C++11 language features is required.])
132     fi
133   else
134     if test x$ac_success = xno; then
135       HAVE_CXX11=0
136       AC_MSG_NOTICE([No compiler with C++11 support was found])
137     else
138       HAVE_CXX11=1
139       AC_DEFINE(HAVE_CXX11,1,
140                 [define if the compiler supports basic C++11 syntax])
141     fi
143     AC_SUBST(HAVE_CXX11)
144   fi