From 3c2183ce07d60194e87cc7df482f621b62b7963b Mon Sep 17 00:00:00 2001 From: "A. Jiang" Date: Tue, 20 Sep 2022 10:06:28 +0800 Subject: [PATCH 1/7] Include in the (no) RTTI test The contents should be skipped when static RTTI is unavailable. --- tests/std/tests/VSO_0000000_has_static_rtti/test.cpp | 4 ++++ 1 file changed, 4 insertions(+) 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..6390a257f3a 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 +#endif // _HAS_CXX17 + using namespace std; #define STATIC_ASSERT(...) static_assert(__VA_ARGS__, #__VA_ARGS__) From e6a6464f5a4e4e1b196281bb8a23999b431f3af3 Mon Sep 17 00:00:00 2001 From: "A. Jiang" Date: Tue, 20 Sep 2022 10:08:12 +0800 Subject: [PATCH 2/7] Skip the contents of when RTTI is unavailable --- stl/inc/any | 8 ++++---- stl/inc/yvals_core.h | 4 +++- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/stl/inc/any b/stl/inc/any index 7bcf69f935a..6a532fc4826 100644 --- a/stl/inc/any +++ b/stl/inc/any @@ -12,16 +12,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 +#if !_HAS_STATIC_RTTI +_EMIT_STL_WARNING(STL4040, "The contents of are available only when RTTI is available."); +#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,6 +443,7 @@ _STD_END _STL_RESTORE_CLANG_WARNINGS #pragma warning(pop) #pragma pack(pop) +#endif // _HAS_STATIC_RTTI #endif // _HAS_CXX17 #endif // _STL_COMPILER_PREPROCESSOR diff --git a/stl/inc/yvals_core.h b/stl/inc/yvals_core.h index 81990761b27..d7f7d7cccf7 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 are available only when RTTI is available." + +// next warning number: STL4041 // next error number: STL1006 From b9c027c72138d274f5b877a537aded8efb34b131 Mon Sep 17 00:00:00 2001 From: "A. Jiang" Date: Tue, 20 Sep 2022 13:30:56 +0800 Subject: [PATCH 3/7] Address @CaseyCarter's review comments Co-authored-by: Casey Carter --- stl/inc/any | 8 +++----- stl/inc/yvals_core.h | 2 +- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/stl/inc/any b/stl/inc/any index 6a532fc4826..e7dd43d43dc 100644 --- a/stl/inc/any +++ b/stl/inc/any @@ -11,9 +11,8 @@ #if !_HAS_CXX17 _EMIT_STL_WARNING(STL4038, "The contents of are available only with C++17 or later."); -#else // ^^^ !_HAS_CXX17 / _HAS_CXX17 vvv -#if !_HAS_STATIC_RTTI -_EMIT_STL_WARNING(STL4040, "The contents of are available only when RTTI is available."); +#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 @@ -443,8 +442,7 @@ _STD_END _STL_RESTORE_CLANG_WARNINGS #pragma warning(pop) #pragma pack(pop) -#endif // _HAS_STATIC_RTTI -#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 d7f7d7cccf7..2462dc6e102 100644 --- a/stl/inc/yvals_core.h +++ b/stl/inc/yvals_core.h @@ -1357,7 +1357,7 @@ _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." -// STL4040 is used to warn that "The contents of are available only when RTTI is available." +// STL4040 is used to warn that "The contents of require static RTTI." // next warning number: STL4041 From 00a401dc6d1527c1932439fcc04f512d32c727f2 Mon Sep 17 00:00:00 2001 From: "Stephan T. Lavavej" Date: Tue, 20 Sep 2022 18:01:39 -0700 Subject: [PATCH 4/7] std.ixx: Guard `` with `_HAS_STATIC_RTTI`. `` is always included first, so `` is available. --- stl/modules/std.ixx | 2 ++ 1 file changed, 2 insertions(+) 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 From a74b6631bc41ee354a176b9a3daf53246a2f8b73 Mon Sep 17 00:00:00 2001 From: "Stephan T. Lavavej" Date: Tue, 20 Sep 2022 18:37:26 -0700 Subject: [PATCH 5/7] Add `/D_HAS_STATIC_RTTI=0` coverage to P2465R3_standard_library_modules. Also reduce the /analyze coverage to one configuration. --- tests/std/include/test_header_units_and_modules.hpp | 4 ++++ tests/std/tests/P2465R3_standard_library_modules/env.lst | 5 ++--- 2 files changed, 6 insertions(+), 3 deletions(-) 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" From 8389342e95c1695bd5d08a8273e851525593f24f Mon Sep 17 00:00:00 2001 From: "Stephan T. Lavavej" Date: Tue, 20 Sep 2022 18:46:01 -0700 Subject: [PATCH 6/7] Guard `__cpp_lib_any` with `_HAS_STATIC_RTTI`, add test coverage. --- stl/inc/yvals_core.h | 4 +++- tests/std/tests/VSO_0157762_feature_test_macros/env.lst | 1 + .../VSO_0157762_feature_test_macros/test.compile.pass.cpp | 2 +- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/stl/inc/yvals_core.h b/stl/inc/yvals_core.h index 2462dc6e102..9075b1aee5e 100644 --- a/stl/inc/yvals_core.h +++ b/stl/inc/yvals_core.h @@ -1478,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/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 From fb4f61700e9ac23282bdaedbc52aaf81801faa58 Mon Sep 17 00:00:00 2001 From: "Stephan T. Lavavej" Date: Tue, 20 Sep 2022 18:54:00 -0700 Subject: [PATCH 7/7] VSO_0000000_has_static_rtti: Comment the apparently unused include. --- tests/std/tests/VSO_0000000_has_static_rtti/test.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 6390a257f3a..f7e89455fea 100644 --- a/tests/std/tests/VSO_0000000_has_static_rtti/test.cpp +++ b/tests/std/tests/VSO_0000000_has_static_rtti/test.cpp @@ -12,7 +12,7 @@ #include #if _HAS_CXX17 -#include +#include // verify that can be included (with no effect) when static RTTI is disabled #endif // _HAS_CXX17 using namespace std;