Contrib: update libarchive to 5.0
[vlc.git] / m4 / stdcxx_14.m4
blobf33253de124a424edf17f35d972dad0cd0ba8471
1 # ============================================================================
2 # Based on http://www.gnu.org/software/autoconf-archive/ax_cxx_compile_stdcxx_11.html
3 # ============================================================================
5 # SYNOPSIS
7 #   AX_CXX_COMPILE_STDCXX_14([ext|noext],[mandatory|optional])
9 # DESCRIPTION
11 #   Check for baseline language coverage in the compiler for the C++14
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++14) or a strict conformance mode (e.g.
16 #   -std=c++14).  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++14 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_CXX14 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>
31 #   Copyright (c) 2014, 2015 Google Inc.
32 #   Copyright (c) 2015, 2019 VLC authors and VideoLAN
34 #   Copying and distribution of this file, with or without modification, are
35 #   permitted in any medium without royalty provided the copyright notice
36 #   and this notice are preserved. This file is offered as-is, without any
37 #   warranty.
39 #serial 7
41 m4_define([_AX_CXX_COMPILE_STDCXX_14_testbody], [[
42   template <typename T>
43     struct check
44     {
45       static_assert(sizeof(int) <= sizeof(T), "not big enough");
46     };
48     struct Base {
49     virtual void f() {}
50     };
51     struct Child : public Base {
52     virtual void f() override {}
53     };
55     typedef check<check<bool>> right_angle_brackets;
57     int a;
58     decltype(a) b;
60     typedef check<int> check_type;
61     check_type c;
62     check_type&& cr = static_cast<check_type&&>(c);
64     auto d = a;
65     auto 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 {
70         struct foo {};
72         template<typename T>
73         using member = typename T::member_type;
75         template<typename T>
76         void func(...) {}
78         template<typename T>
79         void func(member<T>*) {}
81         void test() {
82             func<foo>(0);
83         }
84     }
86     #include <cinttypes>
87     #include <climits>
88     #include <cstddef>
90     constexpr uint64_t constant_u64 = UINT64_C(0x100000000);
91     constexpr unsigned constant_lim = UINT_MAX;
92     const char *constant_fmt = "%" PRIu64, *constant_scn = "%" SCNu64;
93     constexpr size_t constant_align = alignof (std::max_align_t);
95     #include <memory>
97     namespace lambda_init_capture
98     {
99         void foo()
100         {
101             std::unique_ptr<int> ptr(new int);
102             auto lambda = [p = std::move(ptr)](){};
103             lambda();
104         }
105     }
107     #include <type_traits>
109     namespace traits_helper_types
110     {
111         static_assert( std::is_same<char, std::remove_pointer_t<char*>>::value, "plonk" );
112     }
115 AC_DEFUN([AX_CXX_COMPILE_STDCXX_14], [dnl
116   m4_if([$1], [], [],
117         [$1], [ext], [],
118         [$1], [noext], [],
119         [m4_fatal([invalid argument `$1' to AX_CXX_COMPILE_STDCXX_14])])dnl
120   m4_if([$2], [], [ax_cxx_compile_cxx14_required=true],
121         [$2], [mandatory], [ax_cxx_compile_cxx14_required=true],
122         [$2], [optional], [ax_cxx_compile_cxx14_required=false],
123         [m4_fatal([invalid second argument `$2' to AX_CXX_COMPILE_STDCXX_14])])
124   AC_LANG_PUSH([C++])dnl
125   ac_success=no
126   AC_CACHE_CHECK(whether $CXX supports C++14 features by default,
127   ax_cv_cxx_compile_cxx14,
128   [AC_COMPILE_IFELSE([AC_LANG_SOURCE([_AX_CXX_COMPILE_STDCXX_14_testbody])],
129     [ax_cv_cxx_compile_cxx14=yes],
130     [ax_cv_cxx_compile_cxx14=no])])
131   if test x$ax_cv_cxx_compile_cxx14 = xyes; then
132     ac_success=yes
133   fi
135   m4_if([$1], [noext], [], [dnl
136   if test x$ac_success = xno; then
137     for switch in -std=gnu++14 -std=gnu++1y; do
138       cachevar=AS_TR_SH([ax_cv_cxx_compile_cxx14_$switch])
139       AC_CACHE_CHECK(whether $CXX supports C++14 features with $switch,
140                      $cachevar,
141         [ac_save_CXXFLAGS="$CXXFLAGS"
142          CXXFLAGS="$CXXFLAGS $switch"
143          AC_COMPILE_IFELSE([AC_LANG_SOURCE([_AX_CXX_COMPILE_STDCXX_14_testbody])],
144           [eval $cachevar=yes],
145           [eval $cachevar=no])
146          CXXFLAGS="$ac_save_CXXFLAGS"])
147       if eval test x\$$cachevar = xyes; then
148         CXXFLAGS="$CXXFLAGS $switch"
149         ac_success=yes
150         break
151       fi
152     done
153   fi])
155   m4_if([$1], [ext], [], [dnl
156   if test x$ac_success = xno; then
157     for switch in -std=c++14 -std=c++1y; do
158       cachevar=AS_TR_SH([ax_cv_cxx_compile_cxx14_$switch])
159       AC_CACHE_CHECK(whether $CXX supports C++14 features with $switch,
160                      $cachevar,
161         [ac_save_CXXFLAGS="$CXXFLAGS"
162          CXXFLAGS="$CXXFLAGS $switch"
163          AC_COMPILE_IFELSE([AC_LANG_SOURCE([_AX_CXX_COMPILE_STDCXX_14_testbody])],
164           [eval $cachevar=yes],
165           [eval $cachevar=no])
166          CXXFLAGS="$ac_save_CXXFLAGS"])
167       if eval test x\$$cachevar = xyes; then
168         CXXFLAGS="$CXXFLAGS $switch"
169         ac_success=yes
170         break
171       fi
172     done
173   fi])
174   AC_LANG_POP([C++])
175   if test x$ax_cxx_compile_cxx14_required = xtrue; then
176     if test x$ac_success = xno; then
177       AC_MSG_ERROR([*** A compiler with support for C++14 language features is required.])
178     fi
179   else
180     if test x$ac_success = xno; then
181       HAVE_CXX14=0
182       AC_MSG_NOTICE([No compiler with C++14 support was found])
183     else
184       HAVE_CXX14=1
185       AC_DEFINE(HAVE_CXX14,1,
186                 [define if the compiler supports basic C++14 syntax])
187     fi
189     AC_SUBST(HAVE_CXX14)
190   fi