[utility] value_init warning

Hi, I am buiulding trunk vertion of Boost.Test with msvc 8.0 and see following warning: ..\..\..\boost/utility/value_init.hpp(73) : warning C4345: behavior change: an object of POD type constructed with an initializer of the form () will be default-initialized ..\..\..\boost/utility/value_init.hpp(70) : while compiling class template member function 'boost::vinit_detail::non_const_T_base<T>::non_const_T_base(void)' with [ T=arg ] ..\..\..\boost/utility/value_init.hpp(139) : see reference to class template instantiation 'boost::vinit_detail::non_const_T_base<T>' being compiled with [ T=arg ] ..\..\..\boost/mpl/for_each.hpp(72) : see reference to class template instantiation 'boost::value_initialized<T>' being compiled with [ T=arg ] ..\..\..\boost/mpl/for_each.hpp(97) : see reference to function template instantiation 'void boost::mpl::aux::for_each_impl<false>::execute<first,last,TransformOp,F>(Iterator *,LastIterator *,TransformFunc *,F)' being compiled with [ TransformOp=boost::mpl::make_identity<boost::mpl::_>, F=boost::unit_test::ut_detail::generate_test_case_4_type<boost::unit_test::ut_detail::template_test_case_gen<free_test_function,numbers>,free_test_function>, Iterator=first, LastIterator=last, TransformFunc=boost::mpl::make_identity<boost::mpl::_> ] ..\..\..\boost/test/test_case_template.hpp(123) : see reference to function template instantiation 'void boost::mpl::for_each<TestTypesList,boost::mpl::make_identity<T>,boost::unit_test::ut_detail::generate_test_case_4_type<Generator,TestCaseTemplate>>(F,Sequence *,TransformOp *)' being compiled with [ TestTypesList=numbers, T=boost::mpl::_, Generator=boost::unit_test::ut_detail::template_test_case_gen<free_test_function,numbers>, TestCaseTemplate=free_test_function, F=boost::unit_test::ut_detail::generate_test_case_4_type<boost::unit_test::ut_detail::template_test_case_gen<free_test_function,numbers>,free_test_function>, Sequence=numbers, TransformOp=boost::mpl::make_identity<boost::mpl::_> ] ..\..\..\boost/test/test_case_template.hpp(118) : while compiling class template member function 'boost::unit_test::ut_detail::template_test_case_gen<TestCaseTemplate,TestTypesList>::template_test_case_gen(boost::unit_test::const_string)' with [ TestCaseTemplate=free_test_function, TestTypesList=numbers ] test_case_template_example.cpp(27) : see reference to class template instantiation 'boost::unit_test::ut_detail::template_test_case_gen<TestCaseTemplate,TestTypesList>' being compiled with [ TestCaseTemplate=free_test_function, TestTypesList=numbers ] Can we do something about it? Gennadiy

Gennadiy Rozental wrote:
I am building trunk version of Boost.Test with msvc 8.0 and see following warning: ..\..\..\boost/utility/value_init.hpp(73) : warning C4345: behavior change: an object of POD type constructed with an initializer of the form () will be default-initialized
I guess the warning is caused by an MSVC-specific workaround that I committed to trunk/boost/utility/value_init.hpp, September 7, [39157]. My apologizes! The MSVC warning is about the following line of code: new (&x) T(); This line of code looks perfectly fine to me! The warning just tells us that when T is a POD struct, the newly created object will be initialized. As it should! Note that MSVC 7.1 produces the very same warning, so it isn't really a "behavior change" of MSVC 8.0.
Can we do something about it?
Do you have a suggestion? #pragma warning(disable: 4345)? Kind regards, -- Niels Dekker http://www.xs4all.nl/~nd/dekkerware Scientific programmer at LKEB, Leiden University Medical Center

-----Original Message----- From: boost-bounces@lists.boost.org [mailto:boost-bounces@lists.boost.org] On Behalf Of Niels Dekker - mail address until 2008-12-31 Sent: 15 October 2007 13:00 To: boost@lists.boost.org Subject: Re: [boost] [utility] value_init warning
Gennadiy Rozental wrote:
I am building trunk version of Boost.Test with msvc 8.0 and see following warning: ..\..\..\boost/utility/value_init.hpp(73) : warning C4345: behavior change: an object of POD type constructed with an initializer of the form () will be default-initialized
I guess the warning is caused by an MSVC-specific workaround that I committed to trunk/boost/utility/value_init.hpp, September 7, [39157]. My apologizes!
The MSVC warning is about the following line of code: new (&x) T();
This line of code looks perfectly fine to me! The warning just tells us that when T is a POD struct, the newly created object will be initialized. As it should! Note that MSVC 7.1 produces the very same warning, so it isn't really a "behavior change" of MSVC 8.0.
Can we do something about it?
Do you have a suggestion? #pragma warning(disable: 4345)?
Don't forget to push'n'pop the warning level - in case any user finds this warning informative. #ifdef BOOST_MSVC #pragma warning(push) #pragma warning(disable: 4345) #endif ... #ifdef BOOST_MSVC #pragma warning(pop) #endif --- Paul A Bristow Prizet Farmhouse, Kendal, Cumbria UK LA8 8AB +44 1539561830 & SMS, Mobile +44 7714 330204 & SMS pbristow@hetp.u-net.com

#pragma warning(disable: 4345)?
Paul A Bristow wrote:
Don't forget to push'n'pop the warning level - in case any user finds this warning informative.
Thanks! BTW, this warning is only issued by MSVC 7.1 (_MSC_VER 1310), and higher. So I think it should have an extra check, #if _MSC_VER >= 1310. Still there's another warning that might pop up when using value_init, at least on MSVC 8.0: "warning C4351: new behavior: elements of array 'T' will be default initialized." So I guess both warnings should be disabled, within value_init.hpp: #ifdef BOOST_MSVC #pragma warning(push) #if _MSC_VER >= 1310 // MSVC 7.1 or higher. // behavior change: an object of POD type [...] will be default-initialized. #pragma warning(disable: 4345) #endif #if _MSC_VER >= 1400 // MSVC 8.0 or higher. // new behavior: elements of array 'T' will be default initialized. #pragma warning(disable: 4351) #endif #endif ... #ifdef BOOST_MSVC #pragma warning(pop) #endif Right? I wouldn't mind doing the commit :-) But I'll also contact Fernando Cacciola, the creator and owner of value_init. Kind regards, Niels

#pragma warning(disable: 4345)?
Paul A Bristow wrote:
Don't forget to push'n'pop the warning level - in case any user finds this warning informative.
Thanks! BTW, this warning is only issued by MSVC 7.1 (_MSC_VER 1310), and higher. So I think it should have an extra check, #if _MSC_VER >= 1310.
Done! :-) trunk/boost/utility/value_init.hpp: http://svn.boost.org/trac/boost/changeset/40088 Unit test that would have triggered the warning: http://svn.boost.org/trac/boost/changeset/40089
Still there's another warning that might pop up when using value_init, at least on MSVC 8.0: "warning C4351: new behavior: elements of array 'T' will be default initialized."
Hmmm... I *expected* to have that warning as well, but I couldn't reproduce it! (At least, not on the trunk version of value_init.hpp.) So I decided to *only* disable the warning mentioned by Gennadiy Rozental, saying that "an object of POD type constructed with an initializer of the form () will be default-initialized". Thanks for your feedback! Kind regards, Niels
participants (3)
-
Gennadiy Rozental
-
Niels Dekker - mail address until 2008-12-31
-
Paul A Bristow