stdcxx-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elemi...@apache.org
Subject svn commit: r645602 - /stdcxx/trunk/tests/regress/22.locale.stdcxx-554.cpp
Date Mon, 07 Apr 2008 16:44:23 GMT
Author: elemings
Date: Mon Apr  7 09:44:22 2008
New Revision: 645602

URL: http://svn.apache.org/viewvc?rev=645602&view=rev
Log:
2008-04-07  Eric Lemings  <eric.lemings@roguewave.com>

	STDCXX-827
	* tests/regress/22.locale.stdcxx-554.cpp (test_moneypunct,
	test_messages): Use a union containing a pointer to properly
	align storage buffer used for placement new operator.


Modified:
    stdcxx/trunk/tests/regress/22.locale.stdcxx-554.cpp

Modified: stdcxx/trunk/tests/regress/22.locale.stdcxx-554.cpp
URL: http://svn.apache.org/viewvc/stdcxx/trunk/tests/regress/22.locale.stdcxx-554.cpp?rev=645602&r1=645601&r2=645602&view=diff
==============================================================================
--- stdcxx/trunk/tests/regress/22.locale.stdcxx-554.cpp (original)
+++ stdcxx/trunk/tests/regress/22.locale.stdcxx-554.cpp Mon Apr  7 09:44:22 2008
@@ -29,19 +29,24 @@
 
 #include <locale>    // for std::moneypunct, std::messages
 
+enum { fill = '\xdc' };
+
 template <class charT>
 void test_moneypunct (charT)
 {
     typedef std::moneypunct <charT> PunctT;
 
-    const char fill = '\xdc';
+    // Use a pointer to properly align buffer for placment new.
+    union {
+        void* ptr;
+        char buf [sizeof (PunctT) + 1];
+    } u;
 
-    char buf [sizeof (PunctT) + 1];
-    std::memset (buf, fill, sizeof (buf));
+    std::memset (u.buf, fill, sizeof (u.buf));
 
-    PunctT* p = new (buf) PunctT ();
+    PunctT* p = new (u.buf) PunctT ();
 
-    assert (fill == buf [sizeof (PunctT)]);
+    assert (fill == u.buf [sizeof (PunctT)]);
 
     p->~PunctT ();
 }
@@ -51,14 +56,16 @@
 {
     typedef std::messages <charT> MessagesT;
 
-    const char fill = '\xdc';
+    union {
+        void* ptr;
+        char buf [sizeof (MessagesT) + 1];
+    } u;
 
-    char buf [sizeof (MessagesT) + 1];
-    std::memset (buf, fill, sizeof (buf));
+    std::memset (u.buf, fill, sizeof (u.buf));
 
-    MessagesT* p = new (buf) MessagesT ();
+    MessagesT* p = new (u.buf) MessagesT ();
 
-    assert (fill == buf [sizeof (MessagesT)]);
+    assert (fill == u.buf [sizeof (MessagesT)]);
 
     p->~MessagesT ();
 }



Mime
View raw message