Added tests for two more struct types to value_init_test -- discussed with Fernando Cacciola

[SVN r41436]
This commit is contained in:
Niels Dekker 2007-11-28 17:19:37 +00:00
parent 6a2aa822f8
commit 33041ad664

View File

@ -90,6 +90,42 @@ bool operator == ( StringAndInt const& lhs, StringAndInt const& rhs )
{ return lhs.s == rhs.s && lhs.i == rhs.i ; }
//
// A struct that has an explicit (user defined) destructor.
// Some compilers do not correctly value-initialize such a struct, for example:
// Microsoft Visual C++, Feedback ID 100744, "Value-initialization in new-expression"
// https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=100744
//
struct StructWithDestructor
{
int i;
~StructWithDestructor() {}
};
bool operator == ( StructWithDestructor const& lhs, StructWithDestructor const& rhs )
{ return lhs.i == rhs.i ; }
//
// A struct that has a virtual function.
// Some compilers do not correctly value-initialize such a struct either, for example:
// Microsoft Visual C++, Feedback ID 100744, "Value-initialization in new-expression"
// https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=100744
//
struct StructWithVirtualFunction
{
int i;
virtual void VirtualFunction();
};
void StructWithVirtualFunction::VirtualFunction()
{
}
bool operator == ( StructWithVirtualFunction const& lhs, StructWithVirtualFunction const& rhs )
{ return lhs.i == rhs.i ; }
//
// 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.
@ -146,6 +182,18 @@ int test_main(int, char **)
stringAndInt1.s = std::string("1");
BOOST_CHECK ( test(stringAndInt0, stringAndInt1) );
StructWithDestructor structWithDestructor0;
StructWithDestructor structWithDestructor1;
structWithDestructor0.i = 0;
structWithDestructor1.i = 1;
BOOST_CHECK ( test(structWithDestructor0, structWithDestructor1) );
StructWithVirtualFunction structWithVirtualFunction0;
StructWithVirtualFunction structWithVirtualFunction1;
structWithVirtualFunction0.i = 0;
structWithVirtualFunction1.i = 1;
BOOST_CHECK ( test(structWithVirtualFunction0, structWithVirtualFunction1) );
return 0;
}