diff --git a/include/boost/utility/value_init.hpp b/include/boost/utility/value_init.hpp index 8623911..5de9585 100644 --- a/include/boost/utility/value_init.hpp +++ b/include/boost/utility/value_init.hpp @@ -10,6 +10,7 @@ // 21 Ago 2008 (Added swap) Niels Dekker, Fernando Cacciola // 20 Feb 2009 (Fixed logical const-ness issues) Niels Dekker, Fernando Cacciola // 03 Apr 2010 (Added initialized, suggested by Jeffrey Hellrung, fixing #3472) Niels Dekker +// 30 May 2010 (Made memset call conditional, fixing #3869) Niels Dekker // #ifndef BOOST_UTILITY_VALUE_INIT_21AGO2002_HPP #define BOOST_UTILITY_VALUE_INIT_21AGO2002_HPP @@ -21,6 +22,7 @@ // contains. More details on these issues are at libs/utility/value_init.htm #include +#include // For BOOST_NO_COMPLETE_VALUE_INITIALIZATION. #include #include #include @@ -41,6 +43,23 @@ #endif #endif +#ifdef BOOST_NO_COMPLETE_VALUE_INITIALIZATION + // Implementation detail: The macro BOOST_DETAIL_VALUE_INIT_WORKAROUND_SUGGESTED + // suggests that a workaround should be applied, because of compiler issues + // regarding value-initialization. + #define BOOST_DETAIL_VALUE_INIT_WORKAROUND_SUGGESTED +#endif + +// Implementation detail: The macro BOOST_DETAIL_VALUE_INIT_WORKAROUND +// switches the value-initialization workaround either on or off. +#ifndef BOOST_DETAIL_VALUE_INIT_WORKAROUND + #ifdef BOOST_DETAIL_VALUE_INIT_WORKAROUND_SUGGESTED + #define BOOST_DETAIL_VALUE_INIT_WORKAROUND 1 + #else + #define BOOST_DETAIL_VALUE_INIT_WORKAROUND 0 + #endif +#endif + namespace boost { template @@ -82,10 +101,9 @@ class initialized initialized() { - // Note: the following memset call will become conditional when ticket #3869 is fixed: - // https://svn.boost.org/trac/boost/ticket/3869 reported by Aleksey Gurtovoy. +#if BOOST_DETAIL_VALUE_INIT_WORKAROUND std::memset(&x, 0, sizeof(x)); - +#endif new (wrapper_address()) wrapper(); } diff --git a/value_init.htm b/value_init.htm index 018f63b..4ae9177 100644 --- a/value_init.htm +++ b/value_init.htm @@ -223,37 +223,65 @@ it may in practice still be left uninitialized, because of those 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 aggregates may in some cases -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 aggregates uninitialized, when they +should be value-initialized. Value-initialization of objects of a pointer-to-member type may also +go wrong on various compilers.

-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: - -
- -Microsoft Feedback ID 100744 - Value-initialization in new-expression -
Reported by Pavel Kuznetsov (MetaCommunications Engineering), 2005-07-28 -
- -GCC Bug 30111 - Value-initialization of POD base class doesn't initialize members -
Reported by Jonathan Wakely, 2006-12-07 -
- -GCC Bug 33916 - Default constructor fails to initialize array members -
Reported by Michael Elizabeth Chastain, 2007-10-26 -
- -Borland Report 51854 - Value-initialization: POD struct should be zero-initialized -
Reported by Niels Dekker (LKEB, Leiden University Medical Center), 2007-09-11 -
-
+At the moment of writing, May 2010, the following reported issues regarding +value-initialization are still there in current compiler releases: +

+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.

+ New versions of value_initialized (Boost release version 1.35 or higher) -offer a workaround to these issues: value_initialized will now clear -its internal data, prior to constructing the object that it contains. +offer a workaround to these issues: value_initialized 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 +compiler defect macro BOOST_NO_COMPLETE_VALUE_INITIALIZATION.

Types and objects

@@ -463,7 +491,7 @@ for Boost release version 1.35 (2008), offering a workaround to various compiler


-

Revised 1 May 2010

+

Revised 30 May 2010

© Copyright Fernando Cacciola, 2002 - 2010.