Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ TEST_CONSTEXPR_CXX20 bool test() {

test<std::basic_string<char, std::char_traits<char>, min_allocator<char>>>();
test<std::basic_string<char, std::char_traits<char>, safe_allocator<char>>>();
#ifndef TEST_HAS_NO_NASTY_STRING
#if TEST_STD_VER >= 20
test<nasty_string>();
#endif

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ TEST_CONSTEXPR_CXX20 bool test() {
test_assign<std::u16string>();
test_assign<std::u32string>();
#endif
#ifndef TEST_HAS_NO_NASTY_STRING
#if TEST_STD_VER >= 20
test_assign<nasty_string>();
#endif

Expand Down
34 changes: 7 additions & 27 deletions libcxx/test/support/nasty_string.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <typename T>
Expand Down Expand Up @@ -162,13 +148,8 @@ struct ToNastyChar {
nasty_char text[N];
};

template <std::size_t N>
ToNastyChar(const char (&)[N]) -> ToNastyChar<N>;

template <ToNastyChar t>
constexpr auto to_nasty_char() {
return t;
}
template <ToNastyChar Str>
inline constexpr auto static_nasty_text = Str;

// A macro like MAKE_CSTRING
//
Expand All @@ -178,13 +159,12 @@ constexpr auto to_nasty_char() {
# define CONVERT_TO_CSTRING(CHAR, STR) \
[]<class CharT> { \
if constexpr (std::is_same_v<CharT, nasty_char>) { \
static constexpr auto result = to_nasty_char<STR>(); \
return result.text; \
return static_nasty_text<STR>.text; \
} else \
return MAKE_CSTRING(CharT, STR); \
}.template operator()<CHAR>() /* */
#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
Loading