[gcc(refs/vendors/ARM/heads/arm-9-branch)] PR libstdc++/78552 only construct std::locale for C locale once

Joey Ye jye2@gcc.gnu.org
Thu Feb 27 10:56:00 GMT 2020


https://gcc.gnu.org/g:84a5534ce2f8233e6fe9c957ec51a2328bfe60e3

commit 84a5534ce2f8233e6fe9c957ec51a2328bfe60e3
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Wed Feb 26 14:00:07 2020 +0000

    PR libstdc++/78552 only construct std::locale for C locale once
    
    Backport from mainline
    2019-10-09  Jonathan Wakely  <jwakely@redhat.com>
    
    	PR libstdc++/78552
    	* src/c++98/locale_init.cc (locale::classic()): Do not construct a new
    	locale object for every call.
    	(locale::_S_initialize_once()): Construct C locale here.

Diff:
---
 libstdc++-v3/ChangeLog                | 10 ++++++++++
 libstdc++-v3/src/c++98/locale_init.cc |  3 ++-
 2 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog
index 60f2101..19ae4ce 100644
--- a/libstdc++-v3/ChangeLog
+++ b/libstdc++-v3/ChangeLog
@@ -1,3 +1,13 @@
+2020-02-26  Jonathan Wakely  <jwakely@redhat.com>
+
+	Backport from mainline
+	2019-10-09  Jonathan Wakely  <jwakely@redhat.com>
+
+	PR libstdc++/78552
+	* src/c++98/locale_init.cc (locale::classic()): Do not construct a new
+	locale object for every call.
+	(locale::_S_initialize_once()): Construct C locale here.
+
 2020-01-24  Jonathan Wakely  <jwakely@redhat.com>
 
 	Backport from mainline
diff --git a/libstdc++-v3/src/c++98/locale_init.cc b/libstdc++-v3/src/c++98/locale_init.cc
index e5e9d74..07d95dc 100644
--- a/libstdc++-v3/src/c++98/locale_init.cc
+++ b/libstdc++-v3/src/c++98/locale_init.cc
@@ -303,7 +303,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   locale::classic()
   {
     _S_initialize();
-    return *(new (&c_locale) locale(_S_classic));
+    return *(const locale*)c_locale;
   }
 
   void
@@ -313,6 +313,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
     // One reference for _S_classic, one for _S_global
     _S_classic = new (&c_locale_impl) _Impl(2);
     _S_global = _S_classic;
+    new (&c_locale) locale(_S_classic);
   }
 
   void



More information about the Libstdc++-cvs mailing list