Skip to content

Commit 0afa408

Browse files
committed
autotools: update m4 for C++17
1 parent f984a6a commit 0afa408

File tree

1 file changed

+59
-5
lines changed

1 file changed

+59
-5
lines changed

m4/ax_cxx_compile_stdcxx.m4

+59-5
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@
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
@@ -35,13 +35,15 @@
3535
# Copyright (c) 2015 Moritz Klammler <[email protected]>
3636
# Copyright (c) 2016, 2018 Krzesimir Nowak <[email protected]>
3737
# Copyright (c) 2019 Enji Cooper <[email protected]>
38+
# Copyright (c) 2020 Jason Merrill <[email protected]>
39+
# Copyright (c) 2021 Jörn Heusipp <[email protected]>
3840
#
3941
# Copying and distribution of this file, with or without modification, are
4042
# permitted in any medium without royalty provided the copyright notice
4143
# and this notice are preserved. This file is offered as-is, without any
4244
# warranty.
4345

44-
#serial 11
46+
#serial 14
4547

4648
dnl This macro is based on the code from the AX_CXX_COMPILE_STDCXX_11 macro
4749
dnl (serial version number 13).
@@ -50,6 +52,7 @@ AC_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], [],
@@ -62,6 +65,16 @@ AC_DEFUN([AX_CXX_COMPILE_STDCXX], [dnl
6265
AC_LANG_PUSH([C++])dnl
6366
ac_success=no
6467
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])
77+
6578
m4_if([$2], [noext], [], [dnl
6679
if test x$ac_success = xno; then
6780
for alternative in ${ax_cxx_compile_alternatives}; do
@@ -140,20 +153,31 @@ m4_define([_AX_CXX_COMPILE_STDCXX_testbody_11],
140153
_AX_CXX_COMPILE_STDCXX_testbody_new_in_11
141154
)
142155

143-
144156
dnl Test body for checking C++14 support
145157

146158
m4_define([_AX_CXX_COMPILE_STDCXX_testbody_14],
147159
_AX_CXX_COMPILE_STDCXX_testbody_new_in_11
148160
_AX_CXX_COMPILE_STDCXX_testbody_new_in_14
149161
)
150162

163+
dnl Test body for checking C++17 support
164+
151165
m4_define([_AX_CXX_COMPILE_STDCXX_testbody_17],
152166
_AX_CXX_COMPILE_STDCXX_testbody_new_in_11
153167
_AX_CXX_COMPILE_STDCXX_testbody_new_in_14
154168
_AX_CXX_COMPILE_STDCXX_testbody_new_in_17
155169
)
156170

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+
157181
dnl Tests for new features in C++11
158182

159183
m4_define([_AX_CXX_COMPILE_STDCXX_testbody_new_in_11], [[
@@ -949,3 +973,33 @@ namespace cxx17
949973
#endif // __cplusplus < 201703L
950974
951975
]])
976+
977+
978+
dnl Tests for new features in C++20
979+
980+
m4_define([_AX_CXX_COMPILE_STDCXX_testbody_new_in_20], [[
981+
982+
#ifndef __cplusplus
983+
984+
#error "This is not a C++ compiler"
985+
986+
#elif __cplusplus < 202002L
987+
988+
#error "This is not a C++20 compiler"
989+
990+
#else
991+
992+
#include <version>
993+
994+
namespace cxx20
995+
{
996+
997+
// As C++20 supports feature test macros in the standard, there is no
998+
// immediate need to actually test for feature availability on the
999+
// Autoconf side.
1000+
1001+
} // namespace cxx20
1002+
1003+
#endif // __cplusplus < 202002L
1004+
1005+
]])

0 commit comments

Comments
 (0)