Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r63638 - in branches/release/libs/utility: . test
From: nielsdekker_at_[hidden]
Date: 2010-07-04 17:56:47


Author: niels_dekker
Date: 2010-07-04 17:56:44 EDT (Sun, 04 Jul 2010)
New Revision: 63638
URL: http://svn.boost.org/trac/boost/changeset/63638

Log:
Merged value_init fixes (extra tests + documentation) from trunk, see #3472, #3869.
Added:
   branches/release/libs/utility/initialized_test.cpp
      - copied unchanged from r61927, /trunk/libs/utility/initialized_test.cpp
   branches/release/libs/utility/initialized_test_fail1.cpp
      - copied unchanged from r61927, /trunk/libs/utility/initialized_test_fail1.cpp
   branches/release/libs/utility/initialized_test_fail2.cpp
      - copied unchanged from r61927, /trunk/libs/utility/initialized_test_fail2.cpp
   branches/release/libs/utility/value_init_workaround_test.cpp
      - copied, changed from r63015, /trunk/libs/utility/value_init_workaround_test.cpp
Properties modified:
   branches/release/libs/utility/value_init.htm (contents, props changed)
Text files modified:
   branches/release/libs/utility/test/Jamfile.v2 | 4 +
   branches/release/libs/utility/value_init.htm | 140 ++++++++++++++++++++++++++++++++--------
   branches/release/libs/utility/value_init_workaround_test.cpp | 29 +++++++
   3 files changed, 143 insertions(+), 30 deletions(-)

Modified: branches/release/libs/utility/test/Jamfile.v2
==============================================================================
--- branches/release/libs/utility/test/Jamfile.v2 (original)
+++ branches/release/libs/utility/test/Jamfile.v2 2010-07-04 17:56:44 EDT (Sun, 04 Jul 2010)
@@ -32,9 +32,13 @@
         [ compile result_of_test.cpp ]
         [ run ../shared_iterator_test.cpp ]
         [ run ../value_init_test.cpp ]
+ [ run ../value_init_workaround_test.cpp ]
+ [ run ../initialized_test.cpp ]
         [ compile-fail ../value_init_test_fail1.cpp ]
         [ compile-fail ../value_init_test_fail2.cpp ]
         [ compile-fail ../value_init_test_fail3.cpp ]
+ [ compile-fail ../initialized_test_fail1.cpp ]
+ [ compile-fail ../initialized_test_fail2.cpp ]
         [ run ../verify_test.cpp ]
     ;
 

Modified: branches/release/libs/utility/value_init.htm
==============================================================================
--- branches/release/libs/utility/value_init.htm (original)
+++ branches/release/libs/utility/value_init.htm 2010-07-04 17:56:44 EDT (Sun, 04 Jul 2010)
@@ -33,6 +33,7 @@
                    
 <ul>
           <li>template class value_initialized<T></li>
+ <li>template class initialized<T></li>
           <li>initialized_value</li>
                    
 </ul>
@@ -123,6 +124,12 @@
 </pre>
 </p>
 <p>
+The template initialized
+offers both value-initialization and direct-initialization.
+It is especially useful as a data member type, allowing the very same object
+to be either direct-initialized or value-initialized.
+</p>
+<p>
 The <code>const</code> object initialized_value
 allows value-initializing a variable as follows:
 <pre>
@@ -216,37 +223,65 @@
 compiler issues! It's hard to make a general statement on what those issues
 are like, because they depend on the compiler you are using, its version number,
 and the type of object you would like to have value-initialized.
-Compilers usually support value-initialization for built-in types properly.
-But objects of user-defined types that involve <em>aggregates</em> may <em>in some cases</em>
-be partially, or even entirely left uninitialized, when they should be value-initialized.
+All compilers we have tested so far support value-initialization for arithmetic types properly.
+However, various compilers may leave some types of <em>aggregates</em> uninitialized, when they
+should be value-initialized. Value-initialization of objects of a pointer-to-member type may also
+go wrong on various compilers.
 </p>
 <p>
-We have encountered issues regarding value-initialization on compilers by
-Microsoft, Sun, Borland, and GNU. Here is a list of bug reports on those issues:
-<table summary="Compiler bug reports regarding value-initialization" border="0" cellpadding="7" cellspacing="1" >
-<tr><td>
-<a href="https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=100744">
-Microsoft Feedback ID 100744 - Value-initialization in new-expression</a>
-<br>Reported by Pavel Kuznetsov (MetaCommunications Engineering), 2005-07-28
-<br>
-<a href="http://gcc.gnu.org/bugzilla/show_bug.cgi?id=30111">
-GCC Bug 30111 - Value-initialization of POD base class doesn't initialize members</a>
-<br>Reported by Jonathan Wakely, 2006-12-07
-<br>
-<a href="http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33916">
-GCC Bug 33916 - Default constructor fails to initialize array members</a>
-<br>Reported by Michael Elizabeth Chastain, 2007-10-26
-<br>
-<a href="http://qc.codegear.com/wc/qcmain.aspx?d=51854">
-Borland Report 51854 - Value-initialization: POD struct should be zero-initialized</a>
-<br>Reported by Niels Dekker (LKEB, Leiden University Medical Center), 2007-09-11
-<br>
-</td></tr></table>
+At the moment of writing, May 2010, the following reported issues regarding
+value-initialization are still there in current compiler releases:
+<ul>
+<li>
+<a href="https://connect.microsoft.com/VisualStudio/feedback/details/100744">
+Microsoft Visual Studio Feedback ID 100744, Value-initialization in new-expression</a>
+<br>Reported by Pavel Kuznetsov (MetaCommunications Engineering), 2005
+</li><li>
+<a href="http://connect.microsoft.com/VisualStudio/feedback/details/484295">
+Microsoft Visual Studio Feedback ID 484295, VC++ does not value-initialize members of derived classes without user-declared constructor</a>
+<br>Reported by Sylvester Hesp, 2009
+</li><li>
+<a href="https://connect.microsoft.com/VisualStudio/feedback/details/499606">
+Microsoft Visual Studio Feedback ID 499606, Presence of copy constructor breaks member class initialization</a>
+<br>Reported by Alex Vakulenko, 2009
+</li><li>
+<a href="http://qc.embarcadero.com/wc/qcmain.aspx?d=83751">
+Embarcadero/C++Builder Report 83751, Value-initialization: arrays should have each element value-initialized</a>
+<br>Reported by Niels Dekker (LKEB), 2010
+</li><li>
+<a href="http://qc.embarcadero.com/wc/qcmain.aspx?d=83851">
+Embarcadero/C++Builder Report 83851, Value-initialized temporary triggers internal backend error C1798</a>
+<br>Reported by Niels Dekker, 2010
+</li><li>
+<a href="http://qc.embarcadero.com/wc/qcmain.aspx?d=84279">
+Embarcadero/C++Builder Report 84279, Internal compiler error (F1004), value-initializing member function pointer by "new T()"</a>
+<br>Reported by Niels Dekker, 2010
+</li><li>
+Sun CR 6947016, Sun 5.10 may fail to value-initialize an object of a non-POD aggregate.
+<br>Reported to Steve Clamage by Niels Dekker, 2010
+</li><li>
+IBM's XL V10.1 and V11.1 may fail to value-initialize a temporary of a non-POD aggregate.
+<br>Reported to Michael Wong by Niels Dekker, 2010
+</li><li>
+Intel support issue 589832, Attempt to value-initialize pointer-to-member triggers internal error
+on Intel 11.1.
+<br>Reported by John Maddock, 2010
+</li>
+</ul>
+Note that all known GCC issues regarding value-initialization are
+fixed with GCC version 4.4, including
+GCC Bug 30111.
+Clang also has completely implemented value-initialization, as far as we know,
+now that Clang Bug 7139 is fixed.
 </p><p>
+
 New versions of <code>value_initialized</code>
 (Boost release version 1.35 or higher)
-offer a workaround to these issues: <code>value_initialized</code> will now clear
-its internal data, prior to constructing the object that it contains.
+offer a workaround to these issues: <code>value_initialized</code> may now clear
+its internal data, prior to constructing the object that it contains. It will do
+so for those compilers that need to have such a workaround, based on the
+<a href="../config/doc/html/boost_config/boost_macro_reference.html#boost_config.boost_macro_reference.macros_that_describe_defects"
+>compiler defect macro</a> BOOST_NO_COMPLETE_VALUE_INITIALIZATION.
 </p>
                    
 <h2><a name="types"></a>Types and objects</h2>
@@ -340,6 +375,52 @@
                    
 <pre>value_initialized&lt;int&gt; x ;<br>get(x) = 1 ; // OK<br><br>value_initialized&lt;int const&gt; cx ;<br>get(x) = 1 ; // ERROR: Cannot modify a const object<br><br>value_initialized&lt;int&gt; const x_c ;<br>get(x_c) = 1 ; // ERROR: Cannot modify a const object<br><br>value_initialized&lt;int const&gt; const cx_c ;<br>get(cx_c) = 1 ; // ERROR: Cannot modify a const object<br></pre>
 
+<h2><a name="initialized"><code>template class initialized&lt;T&gt;</code></a></h2>
+
+<pre>namespace boost {<br><br>template&lt;class T&gt;<br>class initialized<br>{
+<br> public :
+<br> initialized() : x() {}
+<br> explicit initialized(T const &amp; arg) : x(arg) {}
+<br> operator T const &amp;() const;
+<br> operator T&amp;();
+<br> T const &amp;data() const;
+<br> T&amp; data();
+<br> void swap( value_initialized&lt;T&gt;&amp; );
+<br>
+<br> private :
+<br> <i>unspecified</i> x ;
+<br>} ;
+<br>
+<br>template&lt;class T&gt;
+<br>T const&amp; get ( initialized&lt;T&gt; const&amp; x );
+<br>
+<br>template&lt;class T&gt;
+<br>T&amp; get ( initialized&lt;T&gt;&amp; x );
+<br>
+<br>} // namespace boost
+<br></pre>
+
+The template class <code>boost::initialized&lt;T&gt;</code> supports both value-initialization
+and direct-initialization, so its interface is a superset of the interface
+of <code>value_initialized&lt;T&gt;</code>: Its default-constructor
+value-initializes the wrapped object just like the default-constructor of
+<code>value_initialized&lt;T&gt;</code>, but <code>boost::initialized&lt;T&gt;</code>
+also offers an extra <code>explicit</code>
+constructor, which direct-initializes the wrapped object by the specified value.
+<p>
+
+<code>initialized&lt;T&gt;</code> is especially useful when the wrapped
+object must be either value-initialized or direct-initialized, depending on
+runtime conditions. For example, <code>initialized&lt;T&gt;</code> could
+hold the value of a data member that may be value-initialized by some
+constructors, and direct-initialized by others.
+On the other hand, if it is known beforehand that the
+object must <i>always</i> be value-initialized, <code>value_initialized&lt;T&gt;</code>
+may be preferable. And if the object must always be
+direct-initialized, none of the two wrappers really needs to be used.
+</p>
+
+
 <h2><a name="initialized_value"><code>initialized_value</code></a></h2>
 
 <pre>
@@ -399,6 +480,9 @@
 <p>value_initialized was reimplemented by Fernando Cacciola and Niels Dekker
 for Boost release version 1.35 (2008), offering a workaround to various compiler issues.
      </p>
+<p><code>boost::initialized</code> was very much inspired by feedback from Edward Diener and
+ Jeffrey Hellrung.
+ </p>
 <p>initialized_value was written by Niels Dekker, and added to Boost release version 1.36 (2008).
      </p>
 <p>Developed by <a href="mailto:fernando_cacciola_at_[hidden]">Fernando Cacciola</a>,
@@ -407,9 +491,9 @@
      </p>
                     
 <hr>
-<p>Revised 03 October 2009</p>
+<p>Revised 30 May 2010</p>
                    
-<p>&copy; Copyright Fernando Cacciola, 2002, 2009.</p>
+<p>&copy; Copyright Fernando Cacciola, 2002 - 2010.</p>
                    
 <p>Distributed under the Boost Software License, Version 1.0. See
 <a href="http://www.boost.org/LICENSE_1_0.txt">www.boost.org/LICENSE_1_0.txt</a></p>

Copied: branches/release/libs/utility/value_init_workaround_test.cpp (from r63015, /trunk/libs/utility/value_init_workaround_test.cpp)
==============================================================================
--- /trunk/libs/utility/value_init_workaround_test.cpp (original)
+++ branches/release/libs/utility/value_init_workaround_test.cpp 2010-07-04 17:56:44 EDT (Sun, 04 Jul 2010)
@@ -6,7 +6,7 @@
 //
 // Test program for the boost::value_initialized<T> workaround.
 //
-// 30 May 2010 (Created) Niels Dekker
+// 17 June 2010 (Created) Niels Dekker
 
 // Switch the workaround off, before inluding "value_init.hpp".
 #define BOOST_DETAIL_VALUE_INIT_WORKAROUND 0
@@ -51,6 +51,30 @@
     return arg.i == 0;
   }
 
+ // Equivalent to the Stats class from GCC Bug 33916,
+ // "Default constructor fails to initialize array members", reported in 2007 by
+ // Michael Elizabeth Chastain: http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33916
+ // and fixed for GCC 4.2.4.
+ class private_int_array_pair
+ {
+ friend bool is_value_initialized(const private_int_array_pair& arg);
+ private:
+ int first[12];
+ int second[12];
+ };
+
+ bool is_value_initialized(const private_int_array_pair& arg)
+ {
+ for ( unsigned i = 0; i < 12; ++i)
+ {
+ if ( (arg.first[i] != 0) || (arg.second[i] != 0) )
+ {
+ return false;
+ }
+ }
+ return true;
+ }
+
   template <typename T>
   bool is_value_initialized(const T(& arg)[2])
   {
@@ -107,7 +131,8 @@
   // TODO More types may be added later.
   const unsigned num_failures =
     FAILED_TO_VALUE_INITIALIZE(boost::value_initialized<derived_struct>()) +
- FAILED_TO_VALUE_INITIALIZE(boost::value_initialized<virtual_destructor_holder[2]>());
+ FAILED_TO_VALUE_INITIALIZE(boost::value_initialized<virtual_destructor_holder[2]>()) +
+ FAILED_TO_VALUE_INITIALIZE(boost::value_initialized<private_int_array_pair>());
 
 #ifdef BOOST_DETAIL_VALUE_INIT_WORKAROUND_SUGGESTED
   // One or more failures are expected.


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