From 8baad19fc197d49e59b462942b68d027d700e3e5 Mon Sep 17 00:00:00 2001 From: YexuanXiao Date: Sat, 26 Jul 2025 17:20:50 +0800 Subject: [PATCH 1/2] Suppress Clang warnings --- tests/std/tests/VSO_0000000_initialize_everything/test.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/std/tests/VSO_0000000_initialize_everything/test.cpp b/tests/std/tests/VSO_0000000_initialize_everything/test.cpp index b5ed1baef83..004197dd8a0 100644 --- a/tests/std/tests/VSO_0000000_initialize_everything/test.cpp +++ b/tests/std/tests/VSO_0000000_initialize_everything/test.cpp @@ -12,6 +12,10 @@ #include #include +#ifdef __clang__ +#pragma clang diagnostic ignored "-Wnontrivial-memcall" +#endif // __clang__ + using namespace std; #ifdef _WIN64 From 6721e2bb07ead7868a42afcd9ad48653c91b0634 Mon Sep 17 00:00:00 2001 From: "Stephan T. Lavavej" Date: Sat, 2 Aug 2025 02:59:19 -0700 Subject: [PATCH 2/2] Refactor garbage_data to use an alignas buffer. --- .../test.cpp | 27 +++++++------------ 1 file changed, 9 insertions(+), 18 deletions(-) diff --git a/tests/std/tests/VSO_0000000_initialize_everything/test.cpp b/tests/std/tests/VSO_0000000_initialize_everything/test.cpp index 004197dd8a0..a41e347078a 100644 --- a/tests/std/tests/VSO_0000000_initialize_everything/test.cpp +++ b/tests/std/tests/VSO_0000000_initialize_everything/test.cpp @@ -12,10 +12,6 @@ #include #include -#ifdef __clang__ -#pragma clang diagnostic ignored "-Wnontrivial-memcall" -#endif // __clang__ - using namespace std; #ifdef _WIN64 @@ -57,30 +53,26 @@ inline bool operator!=(const stateful_allocator& lhs, const stateful_allocato return lhs.state != rhs.state; } -// warning C4582: 'garbage_data>::data': constructor is not implicitly called -// warning C4583: 'garbage_data>::data': destructor is not implicitly called -#pragma warning(push) -#pragma warning(disable : 4582 4583) template -struct garbage_data { - union { - T data; - }; - +class garbage_data { +private: + alignas(T) unsigned char buf[sizeof(T)]; bool constructed; + +public: garbage_data() : constructed(false) { - memset(&data, 0xCC, sizeof(data)); + memset(buf, 0xCC, sizeof(T)); } garbage_data(const garbage_data&) = delete; garbage_data& operator=(const garbage_data&) = delete; T& get() { - return data; + return *ptr(); } T* ptr() { - return &data; + return reinterpret_cast(buf); } T* operator->() { @@ -96,11 +88,10 @@ struct garbage_data { template void construct(Args&&... args) { assert(!constructed); - ::new (static_cast(&data)) T(forward(args)...); + ::new (static_cast(buf)) T(forward(args)...); constructed = true; } }; -#pragma warning(pop) template void assert_string_invariants(basic_string, Alloc>& target, const char* const expected) {