Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

<any>: Skip the contents when static RTTI is disabled #3115

Merged
merged 7 commits into from
Sep 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions stl/inc/any
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,15 @@

#if !_HAS_CXX17
_EMIT_STL_WARNING(STL4038, "The contents of <any> 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 <any> require static RTTI.");
#else // ^^^ !_HAS_STATIC_RTTI / _HAS_STATIC_RTTI vvv
#include <initializer_list>
#include <type_traits>
#include <typeinfo>
#include <utility>
#include <xmemory>

#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)
Expand Down Expand Up @@ -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_
8 changes: 6 additions & 2 deletions stl/inc/yvals_core.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <coroutine> are not available with /await."

// next warning number: STL4040
// STL4040 is used to warn that "The contents of <any> require static RTTI."

// next warning number: STL4041

// next error number: STL1006

Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions stl/modules/std.ixx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ export module std;

// "C++ library headers" [tab:headers.cpp]
#include <algorithm>
#if _HAS_STATIC_RTTI
#include <any>
#endif // _HAS_STATIC_RTTI
#include <array>
#include <atomic>
#include <barrier>
Expand Down
4 changes: 4 additions & 0 deletions tests/std/include/test_header_units_and_modules.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <any> when static RTTI is disabled.");
#else // ^^^ static RTTI is disabled / static RTTI is enabled vvv
puts("Testing <any>.");
any a1{1729};
any a2{7.5};
a1.swap(a2);
assert(any_cast<double>(a1) == 7.5);
assert(any_cast<int>(a2) == 1729);
#endif // ^^^ static RTTI is enabled ^^^
}

void test_array() {
Expand Down
5 changes: 2 additions & 3 deletions tests/std/tests/P2465R3_standard_library_modules/env.lst
Original file line number Diff line number Diff line change
Expand Up @@ -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"
4 changes: 4 additions & 0 deletions tests/std/tests/VSO_0000000_has_static_rtti/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
#include <typeinfo>
#include <utility>

#if _HAS_CXX17
#include <any> // verify that <any> 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__)
Expand Down
1 change: 1 addition & 0 deletions tests/std/tests/VSO_0157762_feature_test_macros/env.lst
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down