1010#
1111# Check for baseline language coverage in the compiler for the specified
1212# version of the C++ standard. If necessary, add switches to CXX and
13- # CXXCPP to enable support. VERSION may be '11' (for the C++11 standard)
14- # or '14' (for the C++14 standard) .
13+ # CXXCPP to enable support. VERSION may be '11', '14', '17', or '20' for
14+ # the respective C++ standard version .
1515#
1616# The second argument, if specified, indicates whether you insist on an
1717# extended mode (e.g. -std=gnu++11) or a strict conformance mode (e.g.
1818# -std=c++11). If neither is specified, you get whatever works, with
19- # preference for an extended mode.
19+ # preference for no added switch, and then for an extended mode.
2020#
2121# The third argument, if specified 'mandatory' or if left unspecified,
2222# indicates that baseline support for the specified C++ standard is
3333# Copyright (c) 2014, 2015 Google Inc.; contributed by Alexey Sokolov <sokolov@google.com>
3434# Copyright (c) 2015 Paul Norman <penorman@mac.com>
3535# Copyright (c) 2015 Moritz Klammler <moritz@klammler.eu>
36- # Copyright (c) 2016 Krzesimir Nowak <qdlacz@gmail.com>
36+ # Copyright (c) 2016, 2018 Krzesimir Nowak <qdlacz@gmail.com>
37+ # Copyright (c) 2019 Enji Cooper <yaneurabeya@gmail.com>
38+ # Copyright (c) 2020 Jason Merrill <jason@redhat.com>
39+ # Copyright (c) 2021 Jörn Heusipp <osmanx@problemloesungsmaschine.de>
3740#
3841# Copying and distribution of this file, with or without modification, are
3942# permitted in any medium without royalty provided the copyright notice
4043# and this notice are preserved. This file is offered as-is, without any
4144# warranty.
4245
43- # serial 7
46+ # serial 15
4447
4548dnl This macro is based on the code from the AX_CXX_COMPILE_STDCXX_11 macro
4649dnl (serial version number 13).
4750
48- AX_REQUIRE_DEFINED ( [ AC_MSG_WARN] )
4951AC_DEFUN ( [ AX_CXX_COMPILE_STDCXX ] , [ dnl
5052 m4_if ( [ $1 ] , [ 11] , [ ax_cxx_compile_alternatives="11 0x"] ,
5153 [ $1 ] , [ 14] , [ ax_cxx_compile_alternatives="14 1y"] ,
5254 [ $1 ] , [ 17] , [ ax_cxx_compile_alternatives="17 1z"] ,
55+ [ $1 ] , [ 20] , [ ax_cxx_compile_alternatives="20"] ,
5356 [ m4_fatal ( [ invalid first argument `$1 ' to AX_CXX_COMPILE_STDCXX ] ) ] ) dnl
5457 m4_if ( [ $2 ] , [ ] , [ ] ,
5558 [ $2 ] , [ ext] , [ ] ,
@@ -61,14 +64,16 @@ AC_DEFUN([AX_CXX_COMPILE_STDCXX], [dnl
6164 [ m4_fatal ( [ invalid third argument `$3 ' to AX_CXX_COMPILE_STDCXX ] ) ] )
6265 AC_LANG_PUSH ( [ C++] ) dnl
6366 ac_success=no
64- AC_CACHE_CHECK ( whether $CXX supports C++$1 features by default ,
65- ax_cv_cxx_compile_cxx$1 ,
66- [ AC_COMPILE_IFELSE ( [ AC_LANG_SOURCE ( [ _AX_CXX_COMPILE_STDCXX_testbody_$1 ] ) ] ,
67- [ ax_cv_cxx_compile_cxx$1 =yes] ,
68- [ ax_cv_cxx_compile_cxx$1 =no] ) ] )
69- if test x$ax_cv_cxx_compile_cxx$1 = xyes; then
70- ac_success=yes
71- fi
67+
68+ m4_if ( [ $2 ] , [ ] , [ dnl
69+ AC_CACHE_CHECK ( whether $CXX supports C++$1 features by default ,
70+ ax_cv_cxx_compile_cxx$1 ,
71+ [ AC_COMPILE_IFELSE ( [ AC_LANG_SOURCE ( [ _AX_CXX_COMPILE_STDCXX_testbody_$1 ] ) ] ,
72+ [ ax_cv_cxx_compile_cxx$1 =yes] ,
73+ [ ax_cv_cxx_compile_cxx$1 =no] ) ] )
74+ if test x$ax_cv_cxx_compile_cxx$1 = xyes; then
75+ ac_success=yes
76+ fi] )
7277
7378 m4_if ( [ $2 ] , [ noext] , [ ] , [ dnl
7479 if test x$ac_success = xno; then
@@ -139,7 +144,6 @@ AC_DEFUN([AX_CXX_COMPILE_STDCXX], [dnl
139144 [ define if the compiler supports basic C++$1 syntax] )
140145 fi
141146 AC_SUBST ( HAVE_CXX$1 )
142- m4_if ( [ $1 ] , [ 17] , [ AC_MSG_WARN ( [ C++17 is not yet standardized, so the checks may change in incompatible ways anytime] ) ] )
143147] )
144148
145149
@@ -149,20 +153,31 @@ m4_define([_AX_CXX_COMPILE_STDCXX_testbody_11],
149153 _AX_CXX_COMPILE_STDCXX_testbody_new_in_11
150154)
151155
152-
153156dnl Test body for checking C++14 support
154157
155158m4_define ( [ _AX_CXX_COMPILE_STDCXX_testbody_14] ,
156159 _AX_CXX_COMPILE_STDCXX_testbody_new_in_11
157160 _AX_CXX_COMPILE_STDCXX_testbody_new_in_14
158161)
159162
163+ dnl Test body for checking C++17 support
164+
160165m4_define ( [ _AX_CXX_COMPILE_STDCXX_testbody_17] ,
161166 _AX_CXX_COMPILE_STDCXX_testbody_new_in_11
162167 _AX_CXX_COMPILE_STDCXX_testbody_new_in_14
163168 _AX_CXX_COMPILE_STDCXX_testbody_new_in_17
164169)
165170
171+ dnl Test body for checking C++20 support
172+
173+ m4_define ( [ _AX_CXX_COMPILE_STDCXX_testbody_20] ,
174+ _AX_CXX_COMPILE_STDCXX_testbody_new_in_11
175+ _AX_CXX_COMPILE_STDCXX_testbody_new_in_14
176+ _AX_CXX_COMPILE_STDCXX_testbody_new_in_17
177+ _AX_CXX_COMPILE_STDCXX_testbody_new_in_20
178+ )
179+
180+
166181dnl Tests for new features in C++11
167182
168183m4_define ( [ _AX_CXX_COMPILE_STDCXX_testbody_new_in_11] , [ [
@@ -174,7 +189,11 @@ m4_define([_AX_CXX_COMPILE_STDCXX_testbody_new_in_11], [[
174189
175190#error "This is not a C++ compiler"
176191
177- #elif __cplusplus < 201103L
192+ // MSVC always sets __cplusplus to 199711L in older versions; newer versions
193+ // only set it correctly if /Zc:__cplusplus is specified as well as a
194+ // /std:c++NN switch:
195+ // https://devblogs.microsoft.com/cppblog/msvc-now-correctly-reports-__cplusplus/
196+ #elif __cplusplus < 201103L && !defined _MSC_VER
178197
179198#error "This is not a C++11 compiler"
180199
@@ -199,11 +218,13 @@ namespace cxx11
199218
200219 struct Base
201220 {
221+ virtual ~Base() {}
202222 virtual void f() {}
203223 };
204224
205225 struct Derived : public Base
206226 {
227+ virtual ~Derived() override {}
207228 virtual void f() override {}
208229 };
209230
@@ -463,7 +484,7 @@ m4_define([_AX_CXX_COMPILE_STDCXX_testbody_new_in_14], [[
463484
464485#error "This is not a C++ compiler"
465486
466- #elif __cplusplus < 201402L
487+ #elif __cplusplus < 201402L && !defined _MSC_VER
467488
468489#error "This is not a C++14 compiler"
469490
@@ -587,37 +608,25 @@ m4_define([_AX_CXX_COMPILE_STDCXX_testbody_new_in_17], [[
587608
588609#error "This is not a C++ compiler"
589610
590- #elif __cplusplus <= 201402L
611+ #elif __cplusplus < 201703L && !defined _MSC_VER
591612
592613#error "This is not a C++17 compiler"
593614
594615#else
595616
596- #if defined(__clang__)
597- #define REALLY_CLANG
598- #else
599- #if defined(__GNUC__)
600- #define REALLY_GCC
601- #endif
602- #endif
603-
604617#include <initializer_list>
605618#include <utility>
606619#include <type_traits>
607620
608621namespace cxx17
609622{
610623
611- #if !defined(REALLY_CLANG)
612624 namespace test_constexpr_lambdas
613625 {
614626
615- // TODO: test it with clang++ from git
616-
617627 constexpr int foo = [ ] (){return 42;}();
618628
619629 }
620- #endif // !defined(REALLY_CLANG)
621630
622631 namespace test::nested_namespace::definitions
623632 {
@@ -852,12 +861,9 @@ namespace cxx17
852861
853862 }
854863
855- #if !defined(REALLY_CLANG)
856864 namespace test_template_argument_deduction_for_class_templates
857865 {
858866
859- // TODO: test it with clang++ from git
860-
861867 template <typename T1, typename T2>
862868 struct pair
863869 {
@@ -876,7 +882,6 @@ namespace cxx17
876882 }
877883
878884 }
879- #endif // !defined(REALLY_CLANG)
880885
881886 namespace test_non_type_auto_template_parameters
882887 {
@@ -890,12 +895,9 @@ namespace cxx17
890895
891896 }
892897
893- #if !defined(REALLY_CLANG)
894898 namespace test_structured_bindings
895899 {
896900
897- // TODO: test it with clang++ from git
898-
899901 int arr[ 2] = { 1, 2 };
900902 std::pair<int, int> pr = { 1, 2 };
901903
@@ -927,14 +929,10 @@ namespace cxx17
927929 const auto [ x3, y3 ] = f3();
928930
929931 }
930- #endif // !defined(REALLY_CLANG)
931932
932- #if !defined(REALLY_CLANG)
933933 namespace test_exception_spec_type_system
934934 {
935935
936- // TODO: test it with clang++ from git
937-
938936 struct Good {};
939937 struct Bad {};
940938
@@ -952,7 +950,6 @@ namespace cxx17
952950 static_assert (std::is_same_v<Good, decltype(f(g1, g2))>);
953951
954952 }
955- #endif // !defined(REALLY_CLANG)
956953
957954 namespace test_inline_variables
958955 {
@@ -977,6 +974,36 @@ namespace cxx17
977974
978975} // namespace cxx17
979976
980- #endif // __cplusplus <= 201402L
977+ #endif // __cplusplus < 201703L && !defined _MSC_VER
978+
979+ ] ] )
980+
981+
982+ dnl Tests for new features in C++20
983+
984+ m4_define ( [ _AX_CXX_COMPILE_STDCXX_testbody_new_in_20] , [ [
985+
986+ #ifndef __cplusplus
987+
988+ #error "This is not a C++ compiler"
989+
990+ #elif __cplusplus < 202002L && !defined _MSC_VER
991+
992+ #error "This is not a C++20 compiler"
993+
994+ #else
995+
996+ #include <version>
997+
998+ namespace cxx20
999+ {
1000+
1001+ // As C++20 supports feature test macros in the standard, there is no
1002+ // immediate need to actually test for feature availability on the
1003+ // Autoconf side.
1004+
1005+ } // namespace cxx20
1006+
1007+ #endif // __cplusplus < 202002L && !defined _MSC_VER
9811008
9821009] ] )
0 commit comments