[utility] Proposal MSVC workaround for value_initialized - Ticket #1217

The data of the wrapper class boost::value_initialized<T> may not be initialized properly, when using Microsoft Visual C++. The problem is caused by two different compiler issues regarding value initialization. For details, please read the ticket that I submitted yesterday evening (#1217): http://svn.boost.org/trac/boost/ticket/1217 Fernando Cacciola and I developed a new version of value_init.hpp, offering a workaround. The file is attached to the ticket: http://svn.boost.org/trac/boost/attachment/ticket/1217/value_init_MSVC_worka... The workaround version stores the bytes of the T object that is wrapped by value_initialized<T> as an instance of aligned_storage::type. During the construction of value_initialized<T>, it clears the bytes of T (using memset), just before constructing T itself, by placement new: std::memset(&x, 0, sizeof(x)); new (&x) T(); The workaround is enabled by defining a macro, BOOST_UTILITY_VALUE_INIT_WORKAROUND. As I never contributed to a Boost library before, what should I do in order to get this workaround reviewed, and hopefully get it into the library? Kind regards, -- Niels Dekker http://www.xs4all.nl/~nd/dekkerware Scientific programmer at LKEB, Leiden University Medical Center

on Tue Aug 28 2007, "Niels Dekker - mail address until 2008-12-31" <nd_mail_address_valid_until_2008-12-31-AT-xs4all.nl> wrote:
Fernando Cacciola and I developed a new version of value_init.hpp, offering a workaround. The file is attached to the ticket: http://svn.boost.org/trac/boost/attachment/ticket/1217/value_init_MSVC_worka...
The workaround version stores the bytes of the T object that is wrapped by value_initialized<T> as an instance of aligned_storage::type. During the construction of value_initialized<T>, it clears the bytes of T (using memset), just before constructing T itself, by placement new:
std::memset(&x, 0, sizeof(x)); new (&x) T();
The workaround is enabled by defining a macro, BOOST_UTILITY_VALUE_INIT_WORKAROUND.
As I never contributed to a Boost library before, what should I do in order to get this workaround reviewed, and hopefully get it into the library?
Thanks for your work on this! I think Fernando is entirely qualified to review it, and he has commit privileges on the repository, so I've reassigned the ticket to him. -- Dave Abrahams Boost Consulting http://www.boost-consulting.com The Astoria Seminar ==> http://www.astoriaseminar.com

David Abrahams wrote:
Thanks for your work on this! I think Fernando is entirely qualified to review it...
You're welcome! BTW, Borland's implementation of value-initialization isn't entirely correct either. It might need a workaround as well... The following assertion fails on Borland (version 0x582, Turbo C++ Explorer downloaded from www.codegear.com): struct C { int i; }; value_initialized<C> * ptr = new value_initialized<C>(); assert( get(*ptr).i == 0 ); // Fails on Borland 0x582 Kind regards, Niels
participants (2)
-
David Abrahams
-
Niels Dekker - mail address until 2008-12-31