This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[v3] fix locale_init aliasing warning


Return placement construction in locale::classic. Removing:

/home/bje/source/gcc-trunk/libstdc++-v3/src/locale_init.cc:247:
warning: dereferencing type-punned pointer will break strict-aliasing
rules

Pointed out by Ben Elliston.

tested x86_64/linux

-benjamin
2009-01-06  Benjamin Kosnik  <bkoz@redhat.com>

	* src/locale_init.cc (locale::_S_initialize_once): Move construction
	of classic locale...
	(locale::classic): Here.

Index: src/locale_init.cc
===================================================================
--- src/locale_init.cc	(revision 143141)
+++ src/locale_init.cc	(working copy)
@@ -1,4 +1,5 @@
-// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006
+// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 
+// 2009
 // Free Software Foundation, Inc.
 //
 // This file is part of the GNU ISO C++ Library.  This library is free
@@ -242,9 +243,9 @@
 
   const locale&
   locale::classic()
-  {
+  { 
     _S_initialize();
-    return reinterpret_cast<const locale&>(c_locale);
+    return *(new (&c_locale) locale(_S_classic));
   }
 
   void
@@ -254,7 +255,6 @@
     // 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  

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]