The __formatter_fp::_M_localize function just returns an empty string if
the formatting locale is the C locale, as there is nothing to do. But
the caller was assuming that the returned string contains the localized
string. The caller should use the original string if _M_localize returns
an empty string.
libstdc++-v3/ChangeLog:
PR libstdc++/110968
* include/std/format (__formatter_fp::format): Check return
value of _M_localize.
* testsuite/std/format/functions/format.cc: Check classic
locale.
_Optional_locale __loc;
- basic_string_view<_CharT> __str;
basic_string<_CharT> __wstr;
+ basic_string_view<_CharT> __str;
if constexpr (is_same_v<_CharT, char>)
__str = __narrow_str;
else
__wstr = _M_localize(__str, __expc, __fc.locale());
else
__wstr = _M_localize(__str, __expc, __loc.value());
- __str = __wstr;
+ if (!__wstr.empty())
+ __str = __wstr;
}
size_t __width = _M_spec._M_get_width(__fc);
s = std::format(eloc, "{0:#Lg} {0:+#.3Lg} {0:#08.4Lg}", -1234.);
VERIFY( s == "-1.234,00 -1,23e+03 -01.234," );
+ s = std::format(cloc, "{:05L}", -1.0); // PR libstdc++/110968
+ VERIFY( s == "-0001" );
+
// Restore
std::locale::global(cloc);
}