43
43
# and this notice are preserved. This file is offered as-is, without any
44
44
# warranty.
45
45
46
- # serial 14
46
+ # serial 18
47
47
48
48
dnl This macro is based on the code from the AX_CXX_COMPILE_STDCXX_11 macro
49
49
dnl (serial version number 13).
@@ -104,9 +104,18 @@ AC_DEFUN([AX_CXX_COMPILE_STDCXX], [dnl
104
104
dnl HP's aCC needs +std=c++11 according to:
105
105
dnl http://h21007.www2.hp.com/portal/download/files/unprot/aCxx/PDF_Release_Notes/769149-001.pdf
106
106
dnl Cray's crayCC needs "-h std=c++11"
107
+ dnl MSVC needs -std:c++NN for C++17 and later (default is C++14)
107
108
for alternative in ${ax_cxx_compile_alternatives}; do
108
- for switch in -std=c++${alternative} +std=c++${alternative} "-h std=c++${alternative}"; do
109
- cachevar=AS_TR_SH ( [ ax_cv_cxx_compile_cxx$1 _$switch] )
109
+ for switch in -std=c++${alternative} +std=c++${alternative} "-h std=c++${alternative}" MSVC; do
110
+ if test x"$switch" = xMSVC; then
111
+ dnl AS_TR_SH maps both `:` and `=` to `_` so -std:c++17 would collide
112
+ dnl with -std=c++17. We suffix the cache variable name with _MSVC to
113
+ dnl avoid this.
114
+ switch=-std:c++${alternative}
115
+ cachevar=AS_TR_SH ( [ ax_cv_cxx_compile_cxx$1 _${switch}_MSVC] )
116
+ else
117
+ cachevar=AS_TR_SH ( [ ax_cv_cxx_compile_cxx$1 _$switch] )
118
+ fi
110
119
AC_CACHE_CHECK ( whether $CXX supports C++$1 features with $switch ,
111
120
$cachevar ,
112
121
[ ac_save_CXX="$CXX"
@@ -189,7 +198,11 @@ m4_define([_AX_CXX_COMPILE_STDCXX_testbody_new_in_11], [[
189
198
190
199
#error "This is not a C++ compiler"
191
200
192
- #elif __cplusplus < 201103L
201
+ // MSVC always sets __cplusplus to 199711L in older versions; newer versions
202
+ // only set it correctly if /Zc:__cplusplus is specified as well as a
203
+ // /std:c++NN switch:
204
+ // https://devblogs.microsoft.com/cppblog/msvc-now-correctly-reports-__cplusplus/
205
+ #elif __cplusplus < 201103L && !defined _MSC_VER
193
206
194
207
#error "This is not a C++11 compiler"
195
208
@@ -480,7 +493,7 @@ m4_define([_AX_CXX_COMPILE_STDCXX_testbody_new_in_14], [[
480
493
481
494
#error "This is not a C++ compiler"
482
495
483
- #elif __cplusplus < 201402L
496
+ #elif __cplusplus < 201402L && !defined _MSC_VER
484
497
485
498
#error "This is not a C++14 compiler"
486
499
@@ -604,7 +617,7 @@ m4_define([_AX_CXX_COMPILE_STDCXX_testbody_new_in_17], [[
604
617
605
618
#error "This is not a C++ compiler"
606
619
607
- #elif __cplusplus < 201703L
620
+ #elif __cplusplus < 201703L && !defined _MSC_VER
608
621
609
622
#error "This is not a C++17 compiler"
610
623
@@ -970,7 +983,7 @@ namespace cxx17
970
983
971
984
} // namespace cxx17
972
985
973
- #endif // __cplusplus < 201703L
986
+ #endif // __cplusplus < 201703L && !defined _MSC_VER
974
987
975
988
] ] )
976
989
@@ -983,7 +996,7 @@ m4_define([_AX_CXX_COMPILE_STDCXX_testbody_new_in_20], [[
983
996
984
997
#error "This is not a C++ compiler"
985
998
986
- #elif __cplusplus < 202002L
999
+ #elif __cplusplus < 202002L && !defined _MSC_VER
987
1000
988
1001
#error "This is not a C++20 compiler"
989
1002
@@ -1000,6 +1013,6 @@ namespace cxx20
1000
1013
1001
1014
} // namespace cxx20
1002
1015
1003
- #endif // __cplusplus < 202002L
1016
+ #endif // __cplusplus < 202002L && !defined _MSC_VER
1004
1017
1005
1018
] ] )
0 commit comments