aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonathan Wakely <jwakely@redhat.com>2024-12-11 09:37:48 +0000
committerJonathan Wakely <redi@gcc.gnu.org>2024-12-11 10:52:09 +0000
commit1fd7e36e990396c22823cedd068def2aa3b112ce (patch)
tree6f7b14ff239e64b521f6842b715c1269c14f81aa
parente76df3586417d645dd84e8a1ab165605a8924796 (diff)
downloadgcc-1fd7e36e990396c22823cedd068def2aa3b112ce.zip
gcc-1fd7e36e990396c22823cedd068def2aa3b112ce.tar.gz
gcc-1fd7e36e990396c22823cedd068def2aa3b112ce.tar.bz2
libstdc++: Make std::println use locale from ostream (LWG 4088)
This was just approved in Wrocław. libstdc++-v3/ChangeLog: * include/std/ostream (println): Pass stream's locale to std::format, as per LWG 4088. * testsuite/27_io/basic_ostream/print/1.cc: Check std::println with custom locale. Remove unused brit_punc class.
-rw-r--r--libstdc++-v3/include/std/ostream6
-rw-r--r--libstdc++-v3/testsuite/27_io/basic_ostream/print/1.cc18
2 files changed, 13 insertions, 11 deletions
diff --git a/libstdc++-v3/include/std/ostream b/libstdc++-v3/include/std/ostream
index 637aad5..327313a 100644
--- a/libstdc++-v3/include/std/ostream
+++ b/libstdc++-v3/include/std/ostream
@@ -1028,8 +1028,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
inline void
println(ostream& __os, format_string<_Args...> __fmt, _Args&&... __args)
{
- std::print(__os, "{}\n",
- std::format(__fmt, std::forward<_Args>(__args)...));
+ // _GLIBCXX_RESOLVE_LIB_DEFECTS
+ // 4088. println ignores the locale imbued in std::ostream
+ std::print(__os, "{}\n", std::format(__os.getloc(), __fmt,
+ std::forward<_Args>(__args)...));
}
// Defined for C++26, supported as an extension to C++23.
diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/print/1.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/print/1.cc
index cd4b116..183e087 100644
--- a/libstdc++-v3/testsuite/27_io/basic_ostream/print/1.cc
+++ b/libstdc++-v3/testsuite/27_io/basic_ostream/print/1.cc
@@ -63,14 +63,6 @@ test_vprint_nonunicode()
// { dg-output "garbage in . garbage out" }
}
-struct brit_punc : std::numpunct<char>
-{
- std::string do_grouping() const override { return "\3\3"; }
- char do_thousands_sep() const override { return ','; }
- std::string do_truename() const override { return "yes mate"; }
- std::string do_falsename() const override { return "nah bruv"; }
-};
-
void
test_locale()
{
@@ -82,7 +74,7 @@ test_locale()
// The default C locale.
std::locale cloc = std::locale::classic();
- // A custom locale using comma digit separators.
+ // A custom locale using tilde digit separators.
std::locale bloc(cloc, new stream_punc);
{
@@ -101,6 +93,14 @@ test_locale()
std::print(os, "{:L} {}", 12345, 6789);
VERIFY(os.str() == "1~23~45 6789");
}
+
+ {
+ // LWG 4088. println ignores the locale imbued in std::ostream
+ std::ostringstream os;
+ os.imbue(bloc);
+ std::println(os, "{:L} {}", 12345, 6789);
+ VERIFY(os.str() == "1~23~45 6789\n");
+ }
}
void