Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r61176 - trunk/libs/config/test
From: nielsdekker_at_[hidden]
Date: 2010-04-10 07:29:19


Author: niels_dekker
Date: 2010-04-10 07:29:18 EDT (Sat, 10 Apr 2010)
New Revision: 61176
URL: http://svn.boost.org/trac/boost/changeset/61176

Log:
Added value-initialization tests for POD unions.
Text files modified:
   trunk/libs/config/test/boost_no_com_value_init.ipp | 46 +++++++++++++++++++++++++++++++++++++--
   1 files changed, 43 insertions(+), 3 deletions(-)

Modified: trunk/libs/config/test/boost_no_com_value_init.ipp
==============================================================================
--- trunk/libs/config/test/boost_no_com_value_init.ipp (original)
+++ trunk/libs/config/test/boost_no_com_value_init.ipp 2010-04-10 07:29:18 EDT (Sat, 10 Apr 2010)
@@ -59,6 +59,32 @@
   }
 
 
+ union pod_struct_and_int_union
+ {
+ pod_struct first;
+ int second;
+ };
+
+ bool is_zero_initialized(const pod_struct_and_int_union& arg)
+ {
+ // When a union is zero-initialized, its first non-static
+ // named data member is zero-initialized ([dcl.init]).
+ return is_zero_initialized(arg.first);
+ }
+
+
+ union int_and_pod_struct_union
+ {
+ int first;
+ pod_struct second;
+ };
+
+ bool is_zero_initialized(const int_and_pod_struct_union& arg)
+ {
+ return arg.first == 0;
+ }
+
+
   // A class that holds a "magic" enum value.
   // Note: This is not a POD class, because it has a user-defined
   // default constructor.
@@ -214,6 +240,10 @@
     virtual_destructor_holder m_virtual_destructor_holder_array[2];
     non_pod_class m_non_pod;
     non_pod_class m_non_pod_array[2];
+ pod_struct_and_int_union m_pod_struct_and_int_union;
+ pod_struct_and_int_union m_pod_struct_and_int_union_array[2];
+ int_and_pod_struct_union m_int_and_pod_struct_union;
+ int_and_pod_struct_union m_int_and_pod_struct_union_array[2];
 
   public:
     value_initializer()
@@ -253,7 +283,11 @@
     m_virtual_destructor_holder(),
     m_virtual_destructor_holder_array(),
     m_non_pod(),
- m_non_pod_array()
+ m_non_pod_array(),
+ m_pod_struct_and_int_union(),
+ m_pod_struct_and_int_union_array(),
+ m_int_and_pod_struct_union(),
+ m_int_and_pod_struct_union_array()
     {
     }
 
@@ -314,7 +348,13 @@
         (IS_TRUE( is_value_initialized(m_virtual_destructor_holder_array[1]) ) ? 0 : 1) +
         (IS_TRUE( m_non_pod.is_value_initialized() ) ? 0 : 1) +
         (IS_TRUE( m_non_pod_array[0].is_value_initialized() ) ? 0 : 1 ) +
- (IS_TRUE( m_non_pod_array[1].is_value_initialized() ) ? 0 : 1 );
+ (IS_TRUE( m_non_pod_array[1].is_value_initialized() ) ? 0 : 1 ) +
+ (IS_TRUE( is_zero_initialized(m_pod_struct_and_int_union) ) ? 0 : 1) +
+ (IS_TRUE( is_zero_initialized(m_pod_struct_and_int_union_array[0]) ) ? 0 : 1 ) +
+ (IS_TRUE( is_zero_initialized(m_pod_struct_and_int_union_array[1]) ) ? 0 : 1 ) +
+ (IS_TRUE( is_zero_initialized(m_int_and_pod_struct_union) ) ? 0 : 1) +
+ (IS_TRUE( is_zero_initialized(m_int_and_pod_struct_union_array[0]) ) ? 0 : 1 ) +
+ (IS_TRUE( is_zero_initialized(m_int_and_pod_struct_union_array[1]) ) ? 0 : 1 );
       return num_failures;
     }
   };
@@ -331,7 +371,7 @@
     {
       std::cout << "Number of initialization failures on the stack: " << num_failures_on_stack
         << "\nNumber of initialization failures on the heap: " << num_failures_on_heap
- << "\nDetected by boost_no_complete_value_initialization::test() revision 3."
+ << "\nDetected by boost_no_complete_value_initialization::test() revision 4."
         << std::endl;
     }
     return static_cast<int>(num_failures_on_stack + num_failures_on_heap);


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