Boost logo

Boost-Commit :

From: nielsdekker_at_[hidden]
Date: 2007-12-01 07:14:37


Author: niels_dekker
Date: 2007-12-01 07:14:37 EST (Sat, 01 Dec 2007)
New Revision: 41529
URL: http://svn.boost.org/trac/boost/changeset/41529

Log:
Added value_init tests, based upon GCC bug report by Jonathan Wakely. Added URL to Borland bug report.
Text files modified:
   trunk/libs/utility/value_init_test.cpp | 38 ++++++++++++++++++++++++++++++++++++++
   1 files changed, 38 insertions(+), 0 deletions(-)

Modified: trunk/libs/utility/value_init_test.cpp
==============================================================================
--- trunk/libs/utility/value_init_test.cpp (original)
+++ trunk/libs/utility/value_init_test.cpp 2007-12-01 07:14:37 EST (Sat, 01 Dec 2007)
@@ -62,6 +62,9 @@
 
 //
 // Sample aggregate POD struct type
+// Some compilers do not correctly value-initialize such a struct, for example:
+// Borland C++ Report #51854, "Value-initialization: POD struct should be zero-initialized "
+// http://qc.codegear.com/wc/qcmain.aspx?d=51854
 //
 struct AggregatePODStruct
 {
@@ -127,6 +130,29 @@
 
 
 //
+// A struct that is derived from an aggregate POD struct.
+// Some compilers do not correctly value-initialize such a struct, for example:
+// GCC Bugzilla Bug 30111, "Value-initialization of POD base class doesn't initialize members",
+// reported by Jonathan Wakely, http://gcc.gnu.org/bugzilla/show_bug.cgi?id=30111
+//
+struct DerivedFromAggregatePODStruct : AggregatePODStruct
+{
+ DerivedFromAggregatePODStruct() : AggregatePODStruct() {}
+};
+
+//
+// A struct that wraps an aggregate POD struct as data member.
+//
+struct AggregatePODStructWrapper
+{
+ AggregatePODStructWrapper() : dataMember() {}
+ AggregatePODStruct dataMember;
+};
+
+bool operator == ( AggregatePODStructWrapper const& lhs, AggregatePODStructWrapper const& rhs )
+{ return lhs.dataMember == rhs.dataMember ; }
+
+//
 // This test function tests boost::value_initialized<T> for a specific type T.
 // The first argument (y) is assumed have the value of a value-initialized object.
 // Returns true on success.
@@ -194,6 +220,18 @@
   structWithVirtualFunction1.i = 1;
   BOOST_CHECK ( test(structWithVirtualFunction0, structWithVirtualFunction1) );
 
+ DerivedFromAggregatePODStruct derivedFromAggregatePODStruct0;
+ DerivedFromAggregatePODStruct derivedFromAggregatePODStruct1;
+ static_cast<AggregatePODStruct &>(derivedFromAggregatePODStruct0) = zeroInitializedAggregatePODStruct;
+ static_cast<AggregatePODStruct &>(derivedFromAggregatePODStruct1) = nonZeroInitializedAggregatePODStruct;
+ BOOST_CHECK ( test(derivedFromAggregatePODStruct0, derivedFromAggregatePODStruct1) );
+
+ AggregatePODStructWrapper aggregatePODStructWrapper0;
+ AggregatePODStructWrapper aggregatePODStructWrapper1;
+ aggregatePODStructWrapper0.dataMember = zeroInitializedAggregatePODStruct;
+ aggregatePODStructWrapper1.dataMember = nonZeroInitializedAggregatePODStruct;
+ BOOST_CHECK ( test(aggregatePODStructWrapper0, aggregatePODStructWrapper1) );
+
   return 0;
 }
 


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk