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', '14', '17', or '20' for
14- # the respective C++ standard version.
13+ # CXXCPP to enable support. VERSION may be '11', '14', '17', '20', or
14+ # '23' for 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.
3636# Copyright (c) 2016, 2018 Krzesimir Nowak <qdlacz@gmail.com>
3737# Copyright (c) 2019 Enji Cooper <yaneurabeya@gmail.com>
3838# Copyright (c) 2020 Jason Merrill <jason@redhat.com>
39- # Copyright (c) 2021 Jörn Heusipp <osmanx@problemloesungsmaschine.de>
39+ # Copyright (c) 2021, 2024 Jörn Heusipp <osmanx@problemloesungsmaschine.de>
40+ # Copyright (c) 2015, 2022, 2023, 2024 Olly Betts
4041#
4142# Copying and distribution of this file, with or without modification, are
4243# permitted in any medium without royalty provided the copyright notice
4344# and this notice are preserved. This file is offered as-is, without any
4445# warranty.
4546
46- # serial 18
47+ # serial 25
4748
4849dnl This macro is based on the code from the AX_CXX_COMPILE_STDCXX_11 macro
4950dnl (serial version number 13).
@@ -53,6 +54,7 @@ AC_DEFUN([AX_CXX_COMPILE_STDCXX], [dnl
5354 [ $1 ] , [ 14] , [ ax_cxx_compile_alternatives="14 1y"] ,
5455 [ $1 ] , [ 17] , [ ax_cxx_compile_alternatives="17 1z"] ,
5556 [ $1 ] , [ 20] , [ ax_cxx_compile_alternatives="20"] ,
57+ [ $1 ] , [ 23] , [ ax_cxx_compile_alternatives="23"] ,
5658 [ m4_fatal ( [ invalid first argument `$1 ' to AX_CXX_COMPILE_STDCXX ] ) ] ) dnl
5759 m4_if ( [ $2 ] , [ ] , [ ] ,
5860 [ $2 ] , [ ext] , [ ] ,
@@ -159,31 +161,41 @@ AC_DEFUN([AX_CXX_COMPILE_STDCXX], [dnl
159161dnl Test body for checking C++11 support
160162
161163m4_define ( [ _AX_CXX_COMPILE_STDCXX_testbody_11] ,
162- _AX_CXX_COMPILE_STDCXX_testbody_new_in_11
164+ [ _AX_CXX_COMPILE_STDCXX_testbody_new_in_11]
163165)
164166
165167dnl Test body for checking C++14 support
166168
167169m4_define ( [ _AX_CXX_COMPILE_STDCXX_testbody_14] ,
168- _AX_CXX_COMPILE_STDCXX_testbody_new_in_11
169- _AX_CXX_COMPILE_STDCXX_testbody_new_in_14
170+ [ _AX_CXX_COMPILE_STDCXX_testbody_new_in_11
171+ _AX_CXX_COMPILE_STDCXX_testbody_new_in_14]
170172)
171173
172174dnl Test body for checking C++17 support
173175
174176m4_define ( [ _AX_CXX_COMPILE_STDCXX_testbody_17] ,
175- _AX_CXX_COMPILE_STDCXX_testbody_new_in_11
176- _AX_CXX_COMPILE_STDCXX_testbody_new_in_14
177- _AX_CXX_COMPILE_STDCXX_testbody_new_in_17
177+ [ _AX_CXX_COMPILE_STDCXX_testbody_new_in_11
178+ _AX_CXX_COMPILE_STDCXX_testbody_new_in_14
179+ _AX_CXX_COMPILE_STDCXX_testbody_new_in_17]
178180)
179181
180182dnl Test body for checking C++20 support
181183
182184m4_define ( [ _AX_CXX_COMPILE_STDCXX_testbody_20] ,
183- _AX_CXX_COMPILE_STDCXX_testbody_new_in_11
184- _AX_CXX_COMPILE_STDCXX_testbody_new_in_14
185- _AX_CXX_COMPILE_STDCXX_testbody_new_in_17
186- _AX_CXX_COMPILE_STDCXX_testbody_new_in_20
185+ [ _AX_CXX_COMPILE_STDCXX_testbody_new_in_11
186+ _AX_CXX_COMPILE_STDCXX_testbody_new_in_14
187+ _AX_CXX_COMPILE_STDCXX_testbody_new_in_17
188+ _AX_CXX_COMPILE_STDCXX_testbody_new_in_20]
189+ )
190+
191+ dnl Test body for checking C++23 support
192+
193+ m4_define ( [ _AX_CXX_COMPILE_STDCXX_testbody_23] ,
194+ [ _AX_CXX_COMPILE_STDCXX_testbody_new_in_11
195+ _AX_CXX_COMPILE_STDCXX_testbody_new_in_14
196+ _AX_CXX_COMPILE_STDCXX_testbody_new_in_17
197+ _AX_CXX_COMPILE_STDCXX_testbody_new_in_20
198+ _AX_CXX_COMPILE_STDCXX_testbody_new_in_23]
187199)
188200
189201
@@ -201,7 +213,17 @@ m4_define([_AX_CXX_COMPILE_STDCXX_testbody_new_in_11], [[
201213// MSVC always sets __cplusplus to 199711L in older versions; newer versions
202214// only set it correctly if /Zc:__cplusplus is specified as well as a
203215// /std:c++NN switch:
216+ //
204217// https://devblogs.microsoft.com/cppblog/msvc-now-correctly-reports-__cplusplus/
218+ //
219+ // The value __cplusplus ought to have is available in _MSVC_LANG since
220+ // Visual Studio 2015 Update 3:
221+ //
222+ // https://learn.microsoft.com/en-us/cpp/preprocessor/predefined-macros
223+ //
224+ // This was also the first MSVC version to support C++14 so we can't use the
225+ // value of either __cplusplus or _MSVC_LANG to quickly rule out MSVC having
226+ // C++11 or C++14 support, but we can check _MSVC_LANG for C++17 and later.
205227#elif __cplusplus < 201103L && !defined _MSC_VER
206228
207229#error "This is not a C++11 compiler"
@@ -617,7 +639,7 @@ m4_define([_AX_CXX_COMPILE_STDCXX_testbody_new_in_17], [[
617639
618640#error "This is not a C++ compiler"
619641
620- #elif __cplusplus < 201703L && !defined _MSC_VER
642+ #elif (defined _MSVC_LANG ? _MSVC_LANG : __cplusplus) < 201703L
621643
622644#error "This is not a C++17 compiler"
623645
@@ -983,7 +1005,7 @@ namespace cxx17
9831005
9841006} // namespace cxx17
9851007
986- #endif // __cplusplus < 201703L && !defined _MSC_VER
1008+ #endif // (defined _MSVC_LANG ? _MSVC_LANG : __cplusplus) < 201703L
9871009
9881010] ] )
9891011
@@ -996,7 +1018,7 @@ m4_define([_AX_CXX_COMPILE_STDCXX_testbody_new_in_20], [[
9961018
9971019#error "This is not a C++ compiler"
9981020
999- #elif __cplusplus < 202002L && !defined _MSC_VER
1021+ #elif (defined _MSVC_LANG ? _MSVC_LANG : __cplusplus) < 202002L
10001022
10011023#error "This is not a C++20 compiler"
10021024
@@ -1013,6 +1035,36 @@ namespace cxx20
10131035
10141036} // namespace cxx20
10151037
1016- #endif // __cplusplus < 202002L && !defined _MSC_VER
1038+ #endif // (defined _MSVC_LANG ? _MSVC_LANG : __cplusplus) < 202002L
1039+
1040+ ] ] )
1041+
1042+
1043+ dnl Tests for new features in C++23
1044+
1045+ m4_define ( [ _AX_CXX_COMPILE_STDCXX_testbody_new_in_23] , [ [
1046+
1047+ #ifndef __cplusplus
1048+
1049+ #error "This is not a C++ compiler"
1050+
1051+ #elif (defined _MSVC_LANG ? _MSVC_LANG : __cplusplus) < 202302L
1052+
1053+ #error "This is not a C++23 compiler"
1054+
1055+ #else
1056+
1057+ #include <version>
1058+
1059+ namespace cxx23
1060+ {
1061+
1062+ // As C++23 supports feature test macros in the standard, there is no
1063+ // immediate need to actually test for feature availability on the
1064+ // Autoconf side.
1065+
1066+ } // namespace cxx23
1067+
1068+ #endif // (defined _MSVC_LANG ? _MSVC_LANG : __cplusplus) < 202302L
10171069
10181070] ] )
0 commit comments