Skip to content

Commit 3e7be49

Browse files
[libc++][test] Test nasty_string in C++20 (#135338)
It seems that we can only rely on C++20 features and make `nasty_string` also tested for MSVC STL.
1 parent 3966292 commit 3e7be49

File tree

3 files changed

+9
-26
lines changed

3 files changed

+9
-26
lines changed

libcxx/test/std/strings/basic.string/string.modifiers/string_append/initializer_list.pass.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ TEST_CONSTEXPR_CXX20 bool test() {
4343

4444
test<std::basic_string<char, std::char_traits<char>, min_allocator<char>>>();
4545
test<std::basic_string<char, std::char_traits<char>, safe_allocator<char>>>();
46-
#ifndef TEST_HAS_NO_NASTY_STRING
46+
#if TEST_STD_VER >= 20
4747
test<nasty_string>();
4848
#endif
4949

libcxx/test/std/strings/basic.string/string.modifiers/string_assign/string.pass.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ TEST_CONSTEXPR_CXX20 bool test() {
7474
test_assign<std::u16string>();
7575
test_assign<std::u32string>();
7676
#endif
77-
#ifndef TEST_HAS_NO_NASTY_STRING
77+
#if TEST_STD_VER >= 20
7878
test_assign<nasty_string>();
7979
#endif
8080

libcxx/test/support/nasty_string.h

Lines changed: 7 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -23,21 +23,7 @@
2323
// library uses the provided `CharTraits` instead of using operations on
2424
// the value_type directly.
2525

26-
27-
// When using the code during constant evaluation it relies on
28-
// P2647R1 Permitting static constexpr variables in constexpr functions
29-
// This is a C++23 feature, which is not supported by all compilers yet.
30-
// * GCC >= 13
31-
// * Clang >= 16
32-
// * MSVC no support yet
33-
//
34-
// TODO After there is proper compiler support use TEST_STD_VER >= 23 instead
35-
// of this macro in the tests.
36-
#if TEST_STD_VER < 23 || __cpp_constexpr < 202211L
37-
# define TEST_HAS_NO_NASTY_STRING
38-
#endif
39-
40-
#ifndef TEST_HAS_NO_NASTY_STRING
26+
#if TEST_STD_VER >= 20
4127
// Make sure the char-like operations in strings do not depend on the char-like type.
4228
struct nasty_char {
4329
template <typename T>
@@ -165,10 +151,8 @@ struct ToNastyChar {
165151
template <std::size_t N>
166152
ToNastyChar(const char (&)[N]) -> ToNastyChar<N>;
167153

168-
template <ToNastyChar t>
169-
constexpr auto to_nasty_char() {
170-
return t;
171-
}
154+
template <ToNastyChar Str>
155+
inline constexpr auto static_nasty_text = Str;
172156

173157
// A macro like MAKE_CSTRING
174158
//
@@ -178,13 +162,12 @@ constexpr auto to_nasty_char() {
178162
# define CONVERT_TO_CSTRING(CHAR, STR) \
179163
[]<class CharT> { \
180164
if constexpr (std::is_same_v<CharT, nasty_char>) { \
181-
static constexpr auto result = to_nasty_char<STR>(); \
182-
return result.text; \
165+
return static_nasty_text<STR>.text; \
183166
} else \
184167
return MAKE_CSTRING(CharT, STR); \
185168
}.template operator()<CHAR>() /* */
186-
#else // TEST_HAS_NO_NASTY_STRING
169+
#else // TEST_STD_VER >= 20
187170
# define CONVERT_TO_CSTRING(CharT, STR) MAKE_CSTRING(CharT, STR)
188-
#endif // TEST_HAS_NO_NASTY_STRING
171+
#endif // TEST_STD_VER >= 20
189172

190-
#endif // TEST_SUPPORT_NASTY_STRING_H
173+
#endif // TEST_SUPPORT_NASTY_STRING_H

0 commit comments

Comments
 (0)