Simplfy dg-options in format/debug.cc, by not configuring wide encoding.
Address TODO in format_kind.cc, by adding test for format_kind::map.
libstdc++-v3/ChangeLog:
* testsuite/std/format/ranges/format_kind.cc: Add test for
range_format::map.
* testsuite/std/format/debug.cc: Guard wchar_t usages with
_GLIBCXX_USE_WCHAR_T and simplify dg-options.
* testsuite/std/format/ranges/adaptors.cc: Guard wchar_t
usages with _GLIBCXX_USE_WCHAR_T.
* testsuite/std/format/ranges/formatter.cc: Likewise.
* testsuite/std/format/ranges/string.cc: Likewise.
* testsuite/std/format/ranges/map.cc: Likewise and removed
unused is_format_string_for for wchar_t.
* testsuite/std/format/ranges/sequence.cc: Likewise with
removal.
* testsuite/std/format/tuple.cc: Likewise with removal.
---
Tested with x86_64-linux both with and without --disable-wchar_t.
There are more failing testcases in format directory, but I this
one were easier to adjust as they template on wchar_t.
OK for trunk?
libstdc++-v3/testsuite/std/format/debug.cc | 69 +++++++++++--------
.../testsuite/std/format/ranges/adaptors.cc | 2 +
.../std/format/ranges/format_kind.cc | 4 +-
.../testsuite/std/format/ranges/formatter.cc | 6 +-
.../testsuite/std/format/ranges/map.cc | 14 +---
.../testsuite/std/format/ranges/sequence.cc | 16 ++---
.../testsuite/std/format/ranges/string.cc | 14 ++--
libstdc++-v3/testsuite/std/format/tuple.cc | 17 ++---
8 files changed, 69 insertions(+), 73 deletions(-)
diff --git a/libstdc++-v3/testsuite/std/format/debug.cc
b/libstdc++-v3/testsuite/std/format/debug.cc
index 965b4dfbebc..0ce9801b784 100644
--- a/libstdc++-v3/testsuite/std/format/debug.cc
+++ b/libstdc++-v3/testsuite/std/format/debug.cc
@@ -1,5 +1,4 @@
-// { dg-options "-fexec-charset=UTF-8 -fwide-exec-charset=UTF-32LE
-DUNICODE_ENC" { target le } }
-// { dg-options "-fexec-charset=UTF-8 -fwide-exec-charset=UTF-32BE
-DUNICODE_ENC" { target be } }
+// { dg-options "-fexec-charset=UTF-8 -DUNICODE_ENC" }
// { dg-do run { target c++23 } }
// { dg-require-effective-target 4byte_wchar_t }
// { dg-add-options no_pch }
@@ -12,18 +11,19 @@ std::string
fdebug(char t)
{ return std::format("{:?}", t); }
-std::wstring
-fdebug(wchar_t t)
-{ return std::format(L"{:?}", t); }
-
std::string
fdebug(std::string_view t)
{ return std::format("{:?}", t); }
+#ifdef _GLIBCXX_USE_WCHAR_T
std::wstring
-fdebug(std::wstring_view t)
+fdebug(wchar_t t)
{ return std::format(L"{:?}", t); }
+std::wstring
+fdebug(std::wstring_view t)
+{ return std::format(L"{:?}", t); }
+#endif // _GLIBCXX_USE_WCHAR_T
#define WIDEN_(C, S) ::std::__format::_Widen<C>(S, L##S)
#define WIDEN(S) WIDEN_(_CharT, S)
@@ -244,27 +244,31 @@ test_ill_formed_utf8_seq()
#endif // UNICODE_ENC
}
+template<typename _CharT>
void
test_ill_formed_utf32()
{
#if UNICODE_ENC
- std::wstring res;
+ if constexpr (sizeof(_CharT) >= 4)
+ {
+ std::basic_string<_CharT> res;
- wchar_t ic1 = static_cast<wchar_t>(0xff'ffff);
- res = fdebug(ic1);
- VERIFY( res == LR"('\x{ffffff}')" );
+ _CharT ic1 = static_cast<_CharT>(0xff'ffff);
+ res = fdebug(ic1);
+ VERIFY( res == WIDEN(R"('\x{ffffff}')") );
- std::wstring is1(1, ic1);
- res = fdebug(is1);
- VERIFY( res == LR"("\x{ffffff}")" );
+ std::basic_string<_CharT> is1(1, ic1);
+ res = fdebug(is1);
+ VERIFY( res == WIDEN(R"("\x{ffffff}")") );
- wchar_t ic2 = static_cast<wchar_t>(0xffff'ffff);
- res = fdebug(ic2);
- VERIFY( res == LR"('\x{ffffffff}')" );
+ _CharT ic2 = static_cast<_CharT>(0xffff'ffff);
+ res = fdebug(ic2);
+ VERIFY( res == WIDEN(R"('\x{ffffffff}')") );
- std::wstring is2(1, ic2);
- res = fdebug(is2);
- VERIFY( res == LR"("\x{ffffffff}")" );
+ std::basic_string<_CharT> is2(1, ic2);
+ res = fdebug(is2);
+ VERIFY( res == WIDEN(R"("\x{ffffffff}")") );
+ }
#endif // UNICODE_ENC
}
@@ -810,34 +814,41 @@ void
test_formatters_c()
{
test_formatters<char>();
+#ifdef _GLIBCXX_USE_WCHAR_T
test_formatters<wchar_t>();
test_formatter_char<wchar_t, char>();
+#endif // _GLIBCXX_USE_WCHAR_T
}
int main()
{
test_basic_escapes<char>();
- test_basic_escapes<wchar_t>();
test_ascii_escapes<char>();
- test_ascii_escapes<wchar_t>();
test_extended_ascii<char>();
- test_extended_ascii<wchar_t>();
test_unicode_escapes<char>();
- test_unicode_escapes<wchar_t>();
test_grapheme_extend<char>();
- test_grapheme_extend<wchar_t>();
test_replacement_char<char>();
- test_replacement_char<wchar_t>();
test_ill_formed_utf8_seq();
- test_ill_formed_utf32();
test_fill<char>();
- test_fill<wchar_t>();
test_prec<char>();
- test_prec<wchar_t>();
test_padding();
test_formatters_c();
+
+#ifdef _GLIBCXX_USE_WCHAR_T
+ test_basic_escapes<wchar_t>();
+ test_ascii_escapes<wchar_t>();
+ test_extended_ascii<wchar_t>();
+
+ test_unicode_escapes<wchar_t>();
+ test_grapheme_extend<wchar_t>();
+ test_replacement_char<wchar_t>();
+ test_ill_formed_utf32<wchar_t>();
+
+ test_fill<wchar_t>();
+ test_prec<wchar_t>();
+#endif // _GLIBCXX_USE_WCHAR_T
}
diff --git a/libstdc++-v3/testsuite/std/format/ranges/adaptors.cc
b/libstdc++-v3/testsuite/std/format/ranges/adaptors.cc
index daa73aa39bf..6f885e65789 100644
--- a/libstdc++-v3/testsuite/std/format/ranges/adaptors.cc
+++ b/libstdc++-v3/testsuite/std/format/ranges/adaptors.cc
@@ -129,7 +129,9 @@ test_adaptor()
{
test_format_string<Adaptor>();
test_output<char, Adaptor>();
+#ifdef _GLIBCXX_USE_WCHAR_T
test_output<wchar_t, Adaptor>();
+#endif // _GLIBCXX_USE_WCHAR_T
static_assert(!std::formattable<Adaptor<int>, int>);
static_assert(!std::formattable<Adaptor<int>, char32_t>);
diff --git a/libstdc++-v3/testsuite/std/format/ranges/format_kind.cc
b/libstdc++-v3/testsuite/std/format/ranges/format_kind.cc
index 14b9ff20c21..1450fbaebc5 100644
--- a/libstdc++-v3/testsuite/std/format/ranges/format_kind.cc
+++ b/libstdc++-v3/testsuite/std/format/ranges/format_kind.cc
@@ -75,7 +75,9 @@ void test_override()
CustFormat<int, std::range_format::set> setf{1, 2, 3};
VERIFY( std::format("{}", setf) == "{1, 2, 3}" );
- // TODO test map once formatter for pair is implenented
+ CustFormat<std::pair<int, int>, std::range_format::map> mapf
+ {{1, 11}, {2, 22}, {3, 33}};
+ VERIFY( std::format("{}", mapf) == "{1: 11, 2: 22, 3: 33}" );
CustFormat<char, std::range_format::string> stringf{'a', 'b', 'c', 'd'};
VERIFY( std::format("{}", stringf) == "abcd" );
diff --git a/libstdc++-v3/testsuite/std/format/ranges/formatter.cc
b/libstdc++-v3/testsuite/std/format/ranges/formatter.cc
index 00ce9f6dd0c..4b2fcb5db59 100644
--- a/libstdc++-v3/testsuite/std/format/ranges/formatter.cc
+++ b/libstdc++-v3/testsuite/std/format/ranges/formatter.cc
@@ -118,9 +118,11 @@ template<template<typename, typename> class Formatter>
void test_outputs()
{
test_default<char, Formatter>();
- test_default<wchar_t, Formatter>();
test_override<char, Formatter>();
+#ifdef _GLIBCXX_USE_WCHAR_T
+ test_default<wchar_t, Formatter>();
test_override<wchar_t, Formatter>();
+#endif // _GLIBCXX_USE_WCHAR_T
}
void
@@ -146,7 +148,7 @@ struct MyFlatMap : std::flat_map<int, int>
template<typename CharT>
struct std::formatter<MyFlatMap, CharT>
- // This cannot apply format BitVector const&, because formatted type would
+ // This cannot apply format MyFlatMap const&, because formatted type would
// be std::pair<int const&, int const&>, and formatter for
// pair<int const&, int> cannot format it.
: std::range_formatter<MyFlatMap::reference>
diff --git a/libstdc++-v3/testsuite/std/format/ranges/map.cc
b/libstdc++-v3/testsuite/std/format/ranges/map.cc
index 1838480e2cf..1089b2fd8f9 100644
--- a/libstdc++-v3/testsuite/std/format/ranges/map.cc
+++ b/libstdc++-v3/testsuite/std/format/ranges/map.cc
@@ -30,18 +30,6 @@ is_format_string_for(const char* str, Args&&... args)
}
}
-template<typename... Args>
-bool
-is_format_string_for(const wchar_t* str, Args&&... args)
-{
- try {
- (void) std::vformat(str, std::make_wformat_args(args...));
- return true;
- } catch (const std::format_error&) {
- return false;
- }
-}
-
template<typename Rg, typename CharT>
bool is_range_formatter_spec_for(CharT const* spec, Rg&& rg)
{
@@ -153,7 +141,9 @@ template<class Range>
void test_output_c(bool mapIsDefault = false)
{
test_output<char, Range>(mapIsDefault);
+#ifdef _GLIBCXX_USE_WCHAR_T
test_output<wchar_t, Range>(mapIsDefault);
+#endif // _GLIBCXX_USE_WCHAR_T
}
template<template<typename> class RangeT>
diff --git a/libstdc++-v3/testsuite/std/format/ranges/sequence.cc
b/libstdc++-v3/testsuite/std/format/ranges/sequence.cc
index 32242860f10..f252a788dbd 100644
--- a/libstdc++-v3/testsuite/std/format/ranges/sequence.cc
+++ b/libstdc++-v3/testsuite/std/format/ranges/sequence.cc
@@ -30,18 +30,6 @@ is_format_string_for(const char* str, Args&&... args)
}
}
-template<typename... Args>
-bool
-is_format_string_for(const wchar_t* str, Args&&... args)
-{
- try {
- (void) std::vformat(str, std::make_wformat_args(args...));
- return true;
- } catch (const std::format_error&) {
- return false;
- }
-}
-
template<typename Rg, typename CharT>
bool is_range_formatter_spec_for(CharT const* spec, Rg&& rg)
{
@@ -156,14 +144,18 @@ template<typename Cont>
void test_output_cont()
{
test_output<char, Cont&, Cont>();
+#ifdef _GLIBCXX_USE_WCHAR_T
test_output<wchar_t, Cont const&, Cont>();
+#endif // _GLIBCXX_USE_WCHAR_T
}
template<typename View>
void test_output_view()
{
test_output<char, View, int[3]>();
+#ifdef _GLIBCXX_USE_WCHAR_T
test_output<wchar_t, View, int[3]>();
+#endif // _GLIBCXX_USE_WCHAR_T
}
void
diff --git a/libstdc++-v3/testsuite/std/format/ranges/string.cc
b/libstdc++-v3/testsuite/std/format/ranges/string.cc
index cebdd530168..1b2bfef6fee 100644
--- a/libstdc++-v3/testsuite/std/format/ranges/string.cc
+++ b/libstdc++-v3/testsuite/std/format/ranges/string.cc
@@ -21,6 +21,7 @@ is_format_string_for(const char* str, Args&&... args)
}
}
+#ifdef _GLIBCXX_USE_WCHAR_T
template<typename... Args>
bool
is_format_string_for(const wchar_t* str, Args&&... args)
@@ -32,6 +33,7 @@ is_format_string_for(const wchar_t* str, Args&&... args)
return false;
}
}
+#endif // _GLIBCXX_USE_WCHAR_T
template<typename Rg, typename CharT>
bool is_range_formatter_spec_for(CharT const* spec, Rg&& rg)
@@ -54,12 +56,14 @@ void
test_format_string()
{
// only CharT value types are supported
+ VERIFY( !is_range_formatter_spec_for("s", std::vector<int>()) );
+ VERIFY( !is_format_string_for("{:s}", std::vector<int>()) );
+#ifdef _GLIBCXX_USE_WCHAR_T
VERIFY( !is_range_formatter_spec_for(L"s", std::vector<char>()) );
VERIFY( !is_format_string_for(L"{:s}", std::vector<char>()) );
VERIFY( !is_range_formatter_spec_for(L"s", std::vector<char>()) );
VERIFY( !is_format_string_for(L"{:s}", std::vector<char>()) );
- VERIFY( !is_range_formatter_spec_for("s", std::vector<int>()) );
- VERIFY( !is_format_string_for("{:s}", std::vector<int>()) );
+#endif // _GLIBCXX_USE_WCHAR_T
// invalid format stringss
VERIFY( !is_range_formatter_spec_for("?", std::vector<char>()) );
@@ -240,7 +244,6 @@ bool strip_prefix(std::string_view& v, size_t n, char c)
return true;
}
-
void test_padding()
{
std::string res;
@@ -285,6 +288,9 @@ int main()
{
test_format_string();
test_outputs<char>();
- test_outputs<wchar_t>();
test_nested();
+
+#ifdef _GLIBCXX_USE_WCHAR_T
+ test_outputs<wchar_t>();
+#endif // _GLIBCXX_USE_WCHAR_T
}
diff --git a/libstdc++-v3/testsuite/std/format/tuple.cc
b/libstdc++-v3/testsuite/std/format/tuple.cc
index ff0359b9aba..63bafc1364e 100644
--- a/libstdc++-v3/testsuite/std/format/tuple.cc
+++ b/libstdc++-v3/testsuite/std/format/tuple.cc
@@ -26,18 +26,6 @@ is_format_string_for(const char* str, Args&&... args)
}
}
-template<typename... Args>
-bool
-is_format_string_for(const wchar_t* str, Args&&... args)
-{
- try {
- (void) std::vformat(str, std::make_wformat_args(args...));
- return true;
- } catch (const std::format_error&) {
- return false;
- }
-}
-
#define WIDEN_(C, S) ::std::__format::_Widen<C>(S, L##S)
#define WIDEN(S) WIDEN_(_CharT, S)
@@ -346,7 +334,10 @@ int main()
{
test_format_string();
test_outputs<char>();
- test_outputs<wchar_t>();
test_nested();
test_padding();
+
+#ifdef _GLIBCXX_USE_WCHAR_T
+ test_outputs<wchar_t>();
+#endif // _GLIBCXX_USE_WCHAR_T
}
--
2.49.0