diff --git a/stl/inc/format b/stl/inc/format index b6c788828f..438300f2d7 100644 --- a/stl/inc/format +++ b/stl/inc/format @@ -695,10 +695,6 @@ public: : _Active_state(_Basic_format_arg_type::_Int_type), _Int_state(_Val) {} explicit basic_format_arg(const unsigned int _Val) noexcept : _Active_state(_Basic_format_arg_type::_UInt_type), _UInt_state(_Val) {} - explicit basic_format_arg(const long _Val) noexcept - : _Active_state(_Basic_format_arg_type::_Int_type), _Int_state(_Val) {} - explicit basic_format_arg(const unsigned long _Val) noexcept - : _Active_state(_Basic_format_arg_type::_UInt_type), _UInt_state(_Val) {} explicit basic_format_arg(const long long _Val) noexcept : _Active_state(_Basic_format_arg_type::_Long_long_type), _Long_long_state(_Val) {} explicit basic_format_arg(const unsigned long long _Val) noexcept @@ -3548,10 +3544,19 @@ struct _Formatter_base { _FormatCtx.arg(static_cast(_Specs._Dynamic_precision_index))); } - return _STD visit_format_arg( - _Arg_formatter{ - ._Ctx = _STD addressof(_FormatCtx), ._Specs = _STD addressof(_Format_specs)}, - basic_format_arg<_FormatContext>{_Val}); + using _Erased_type = _Format_arg_traits<_FormatContext>::template _Storage_type<_Ty>; + + _Arg_formatter _Visitor{ + ._Ctx = _STD addressof(_FormatCtx), ._Specs = _STD addressof(_Format_specs)}; +#if !_HAS_CXX23 + if constexpr (is_same_v<_Erased_type, basic_string_view<_CharT>>) { + return _STD visit_format_arg( + _Visitor, basic_format_arg<_FormatContext>{_Erased_type{_Val.data(), _Val.size()}}); + } else +#endif // !_HAS_CXX23 + { + return _STD visit_format_arg(_Visitor, basic_format_arg<_FormatContext>{static_cast<_Erased_type>(_Val)}); + } } private: diff --git a/tests/std/tests/P0645R10_text_formatting_custom_formatting/test.cpp b/tests/std/tests/P0645R10_text_formatting_custom_formatting/test.cpp index e1bf232b06..c285fcdbaf 100644 --- a/tests/std/tests/P0645R10_text_formatting_custom_formatting/test.cpp +++ b/tests/std/tests/P0645R10_text_formatting_custom_formatting/test.cpp @@ -96,7 +96,7 @@ struct std::formatter, charT> : std::formatter; static_assert(!is_default_constructible_v); @@ -184,6 +184,21 @@ void test_custom_formattable_type() { test_numeric_custom_formattable_type(); test_numeric_custom_formattable_type(); test_numeric_custom_formattable_type(); + + test_custom_equiv_with_format(STR("{}"), charT(' ')); + test_custom_equiv_with_format(STR("{}"), ' '); + + charT test_str[] = {charT(' '), charT()}; + test_custom_equiv_with_format(STR("{}"), test_str); + test_custom_equiv_with_format(STR("{}"), test_str); + + struct traits : char_traits {}; + test_custom_equiv_with_format, charT>(STR("{}"), test_str); + test_custom_equiv_with_format, charT>(STR("{}"), test_str); + + test_custom_equiv_with_format(STR("{}"), nullptr); + test_custom_equiv_with_format(STR("{}"), nullptr); + test_custom_equiv_with_format(STR("{}"), nullptr); } template @@ -201,6 +216,21 @@ void test_mixed_custom_formattable_type() { test_numeric_mixed_args_custom_formattable_type(); test_numeric_mixed_args_custom_formattable_type(); test_numeric_mixed_args_custom_formattable_type(); + + test_custom_equiv_with_format_mixed(STR("{}{}"), charT(' ')); + test_custom_equiv_with_format_mixed(STR("{}{}"), ' '); + + charT test_str[] = {charT(' '), charT()}; + test_custom_equiv_with_format_mixed(STR("{}{}"), test_str); + test_custom_equiv_with_format_mixed(STR("{}{}"), test_str); + + struct traits : char_traits {}; + test_custom_equiv_with_format_mixed, charT>(STR("{}{}"), test_str); + test_custom_equiv_with_format_mixed, charT>(STR("{}{}"), test_str); + + test_custom_equiv_with_format_mixed(STR("{}{}"), nullptr); + test_custom_equiv_with_format_mixed(STR("{}{}"), nullptr); + test_custom_equiv_with_format_mixed(STR("{}{}"), nullptr); } int main() {