Added value_init tests, based upon GCC bug report by Jonathan Wakely. Added URL to Borland bug report.

[SVN r41529]
This commit is contained in:
Niels Dekker 2007-12-01 12:14:37 +00:00
parent 33041ad664
commit 882d38c2c7

View File

@ -62,6 +62,9 @@ struct NonPOD : NonPODBase
// //
// Sample aggregate POD struct type // 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 struct AggregatePODStruct
{ {
@ -126,6 +129,29 @@ bool operator == ( StructWithVirtualFunction const& lhs, StructWithVirtualFuncti
{ return lhs.i == rhs.i ; } { return lhs.i == rhs.i ; }
//
// 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. // 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. // The first argument (y) is assumed have the value of a value-initialized object.
@ -194,6 +220,18 @@ int test_main(int, char **)
structWithVirtualFunction1.i = 1; structWithVirtualFunction1.i = 1;
BOOST_CHECK ( test(structWithVirtualFunction0, structWithVirtualFunction1) ); 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; return 0;
} }