From 6ecaa2897db7b7c7362fce6919d3726b8b530816 Mon Sep 17 00:00:00 2001 From: "A. Jiang" Date: Fri, 11 Apr 2025 17:49:05 +0800 Subject: [PATCH 1/2] [libc++][test] Test `nasty_string` in C++20 It seems that we can only rely on C++20 features and make `nasty_string` also tested for MSVC STL. Drive-by: Removes an unnecessary deduction guide. --- .../string_append/initializer_list.pass.cpp | 2 +- .../string_assign/string.pass.cpp | 2 +- libcxx/test/support/nasty_string.h | 34 ++++--------------- 3 files changed, 9 insertions(+), 29 deletions(-) diff --git a/libcxx/test/std/strings/basic.string/string.modifiers/string_append/initializer_list.pass.cpp b/libcxx/test/std/strings/basic.string/string.modifiers/string_append/initializer_list.pass.cpp index f1f5828bfe21d..d494cd0435b96 100644 --- a/libcxx/test/std/strings/basic.string/string.modifiers/string_append/initializer_list.pass.cpp +++ b/libcxx/test/std/strings/basic.string/string.modifiers/string_append/initializer_list.pass.cpp @@ -43,7 +43,7 @@ TEST_CONSTEXPR_CXX20 bool test() { test, min_allocator>>(); test, safe_allocator>>(); -#ifndef TEST_HAS_NO_NASTY_STRING +#if TEST_STD_VER >= 20 test(); #endif diff --git a/libcxx/test/std/strings/basic.string/string.modifiers/string_assign/string.pass.cpp b/libcxx/test/std/strings/basic.string/string.modifiers/string_assign/string.pass.cpp index 8b310630bf07a..edd3913fa01f6 100644 --- a/libcxx/test/std/strings/basic.string/string.modifiers/string_assign/string.pass.cpp +++ b/libcxx/test/std/strings/basic.string/string.modifiers/string_assign/string.pass.cpp @@ -74,7 +74,7 @@ TEST_CONSTEXPR_CXX20 bool test() { test_assign(); test_assign(); #endif -#ifndef TEST_HAS_NO_NASTY_STRING +#if TEST_STD_VER >= 20 test_assign(); #endif diff --git a/libcxx/test/support/nasty_string.h b/libcxx/test/support/nasty_string.h index fa4c1b6764314..f98dc1cb7332e 100644 --- a/libcxx/test/support/nasty_string.h +++ b/libcxx/test/support/nasty_string.h @@ -23,21 +23,7 @@ // library uses the provided `CharTraits` instead of using operations on // the value_type directly. - -// When using the code during constant evaluation it relies on -// P2647R1 Permitting static constexpr variables in constexpr functions -// This is a C++23 feature, which is not supported by all compilers yet. -// * GCC >= 13 -// * Clang >= 16 -// * MSVC no support yet -// -// TODO After there is proper compiler support use TEST_STD_VER >= 23 instead -// of this macro in the tests. -#if TEST_STD_VER < 23 || __cpp_constexpr < 202211L -# define TEST_HAS_NO_NASTY_STRING -#endif - -#ifndef TEST_HAS_NO_NASTY_STRING +#if TEST_STD_VER >= 20 // Make sure the char-like operations in strings do not depend on the char-like type. struct nasty_char { template @@ -162,13 +148,8 @@ struct ToNastyChar { nasty_char text[N]; }; -template -ToNastyChar(const char (&)[N]) -> ToNastyChar; - -template -constexpr auto to_nasty_char() { - return t; -} +template +inline constexpr auto static_nasty_text = Str; // A macro like MAKE_CSTRING // @@ -178,13 +159,12 @@ constexpr auto to_nasty_char() { # define CONVERT_TO_CSTRING(CHAR, STR) \ [] { \ if constexpr (std::is_same_v) { \ - static constexpr auto result = to_nasty_char(); \ - return result.text; \ + return static_nasty_text.text; \ } else \ return MAKE_CSTRING(CharT, STR); \ }.template operator()() /* */ -#else // TEST_HAS_NO_NASTY_STRING +#else // TEST_STD_VER >= 20 # define CONVERT_TO_CSTRING(CharT, STR) MAKE_CSTRING(CharT, STR) -#endif // TEST_HAS_NO_NASTY_STRING +#endif // TEST_STD_VER >= 20 -#endif // TEST_SUPPORT_NASTY_STRING_H +#endif // TEST_SUPPORT_NASTY_STRING_H From 653e7fff930181df4a205112a353cf8ef101139a Mon Sep 17 00:00:00 2001 From: "A. Jiang" Date: Fri, 11 Apr 2025 18:17:53 +0800 Subject: [PATCH 2/2] Restore redundant deduction guide to suppress -Wctad-maybe-unsupported --- libcxx/test/support/nasty_string.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/libcxx/test/support/nasty_string.h b/libcxx/test/support/nasty_string.h index f98dc1cb7332e..c2968f52e3a00 100644 --- a/libcxx/test/support/nasty_string.h +++ b/libcxx/test/support/nasty_string.h @@ -148,6 +148,9 @@ struct ToNastyChar { nasty_char text[N]; }; +template +ToNastyChar(const char (&)[N]) -> ToNastyChar; + template inline constexpr auto static_nasty_text = Str;