diff --git a/stl/inc/any b/stl/inc/any index 7bcf69f935a..e7dd43d43dc 100644 --- a/stl/inc/any +++ b/stl/inc/any @@ -11,17 +11,15 @@ #if !_HAS_CXX17 _EMIT_STL_WARNING(STL4038, "The contents of are available only with C++17 or later."); -#else // ^^^ !_HAS_CXX17 / _HAS_CXX17 vvv +#elif !_HAS_STATIC_RTTI // ^^^ !_HAS_CXX17 / _HAS_CXX17 vvv +_EMIT_STL_WARNING(STL4040, "The contents of require static RTTI."); +#else // ^^^ !_HAS_STATIC_RTTI / _HAS_STATIC_RTTI vvv #include #include #include #include #include -#if !_HAS_STATIC_RTTI -#error class any requires static RTTI. -#endif // _HAS_STATIC_RTTI - #pragma pack(push, _CRT_PACKING) #pragma warning(push, _STL_WARNING_LEVEL) #pragma warning(disable : _STL_DISABLED_WARNINGS) @@ -444,7 +442,7 @@ _STD_END _STL_RESTORE_CLANG_WARNINGS #pragma warning(pop) #pragma pack(pop) -#endif // _HAS_CXX17 +#endif // ^^^ _HAS_STATIC_RTTI ^^^ #endif // _STL_COMPILER_PREPROCESSOR #endif // _ANY_ diff --git a/stl/inc/yvals_core.h b/stl/inc/yvals_core.h index 81990761b27..9075b1aee5e 100644 --- a/stl/inc/yvals_core.h +++ b/stl/inc/yvals_core.h @@ -1357,7 +1357,9 @@ _EMIT_STL_ERROR(STL1004, "C++98 unexpected() is incompatible with C++23 unexpect // STL4039 is used to warn that "The contents of are not available with /await." -// next warning number: STL4040 +// STL4040 is used to warn that "The contents of require static RTTI." + +// next warning number: STL4041 // next error number: STL1006 @@ -1476,7 +1478,9 @@ _EMIT_STL_ERROR(STL1004, "C++98 unexpected() is incompatible with C++23 unexpect #define __cpp_lib_void_t 201411L #if _HAS_CXX17 -#define __cpp_lib_any 201606L +#if _HAS_STATIC_RTTI +#define __cpp_lib_any 201606L +#endif // _HAS_STATIC_RTTI #define __cpp_lib_apply 201603L #define __cpp_lib_atomic_is_always_lock_free 201603L #define __cpp_lib_boyer_moore_searcher 201603L diff --git a/stl/modules/std.ixx b/stl/modules/std.ixx index 30f8c0839a3..dbd322f207a 100644 --- a/stl/modules/std.ixx +++ b/stl/modules/std.ixx @@ -37,7 +37,9 @@ export module std; // "C++ library headers" [tab:headers.cpp] #include +#if _HAS_STATIC_RTTI #include +#endif // _HAS_STATIC_RTTI #include #include #include diff --git a/tests/std/include/test_header_units_and_modules.hpp b/tests/std/include/test_header_units_and_modules.hpp index 8d4c700913c..411bdb36f3a 100644 --- a/tests/std/include/test_header_units_and_modules.hpp +++ b/tests/std/include/test_header_units_and_modules.hpp @@ -20,12 +20,16 @@ void test_algorithm() { void test_any() { using namespace std; +#if defined(_HAS_STATIC_RTTI) && _HAS_STATIC_RTTI == 0 // intentional: `import std;` can't provide a default definition + puts("Nothing to test in when static RTTI is disabled."); +#else // ^^^ static RTTI is disabled / static RTTI is enabled vvv puts("Testing ."); any a1{1729}; any a2{7.5}; a1.swap(a2); assert(any_cast(a1) == 7.5); assert(any_cast(a2) == 1729); +#endif // ^^^ static RTTI is enabled ^^^ } void test_array() { diff --git a/tests/std/tests/P2465R3_standard_library_modules/env.lst b/tests/std/tests/P2465R3_standard_library_modules/env.lst index 141724e0d42..bce5b396773 100644 --- a/tests/std/tests/P2465R3_standard_library_modules/env.lst +++ b/tests/std/tests/P2465R3_standard_library_modules/env.lst @@ -13,6 +13,5 @@ PM_CL="/MD" PM_CL="/MDd" PM_CL="/MT" PM_CL="/MTd" -RUNALL_CROSSLIST -PM_CL="" -PM_CL="/analyze:only /analyze:autolog-" +PM_CL="/MDd /analyze:only /analyze:autolog-" +PM_CL="/MDd /GR- /D_HAS_STATIC_RTTI=0" diff --git a/tests/std/tests/VSO_0000000_has_static_rtti/test.cpp b/tests/std/tests/VSO_0000000_has_static_rtti/test.cpp index f3c0d19a44d..f7e89455fea 100644 --- a/tests/std/tests/VSO_0000000_has_static_rtti/test.cpp +++ b/tests/std/tests/VSO_0000000_has_static_rtti/test.cpp @@ -11,6 +11,10 @@ #include #include +#if _HAS_CXX17 +#include // verify that can be included (with no effect) when static RTTI is disabled +#endif // _HAS_CXX17 + using namespace std; #define STATIC_ASSERT(...) static_assert(__VA_ARGS__, #__VA_ARGS__) diff --git a/tests/std/tests/VSO_0157762_feature_test_macros/env.lst b/tests/std/tests/VSO_0157762_feature_test_macros/env.lst index c009f8550aa..11b8cdb9e31 100644 --- a/tests/std/tests/VSO_0157762_feature_test_macros/env.lst +++ b/tests/std/tests/VSO_0157762_feature_test_macros/env.lst @@ -37,6 +37,7 @@ PM_COMPILER="clang-cl" PM_CL="-fno-ms-compatibility -fno-delayed-template-parsin # The following lines are extras not present in usual_matrix.lst PM_CL="/MT /std:c++latest /permissive- /EHsc /D_HAS_STD_BYTE=0" +PM_CL="/MT /std:c++latest /permissive- /EHsc /GR- /D_HAS_STATIC_RTTI=0" PM_CL="/MT /std:c++14 /permissive- /EHsc /await:strict" PM_CL="/MT /std:c++14 /permissive- /EHsc /Zc:char8_t" PM_CL="/MT /std:c++17 /permissive- /EHsc /Zc:char8_t" diff --git a/tests/std/tests/VSO_0157762_feature_test_macros/test.compile.pass.cpp b/tests/std/tests/VSO_0157762_feature_test_macros/test.compile.pass.cpp index 0913ac86e86..d1da9e6ebe1 100644 --- a/tests/std/tests/VSO_0157762_feature_test_macros/test.compile.pass.cpp +++ b/tests/std/tests/VSO_0157762_feature_test_macros/test.compile.pass.cpp @@ -66,7 +66,7 @@ STATIC_ASSERT(__cpp_lib_allocate_at_least == 202106L); STATIC_ASSERT(__cpp_lib_allocator_traits_is_always_equal == 201411L); #endif -#if _HAS_CXX17 +#if _HAS_CXX17 && _HAS_STATIC_RTTI #ifndef __cpp_lib_any #error __cpp_lib_any is not defined #elif __cpp_lib_any != 201606L