Boost C++ Libraries: Ticket #2548: Let's fix the logical constness of value_initialized! https://svn.boost.org/trac10/ticket/2548 <p> The data() member function and the conversion operator of boost::value_initialized&lt;T&gt; break the logical constness: both functions are declared "const", while they return a non-const reference to the T object that is owned by value_initialized&lt;T&gt;. I think both of them should be replaced by a pair of overloaded functions for const and non-const access. </p> <p> I don't think that there ever was a good reason for the data() function to break the logical constness. But clearly, there <em>was</em> a reason for the conversion operator to do so, at the time value_initialized was first released, in 2002. At that time, some commonly used compilers would complain about ambiguity when the conversion operator would be overloaded for const and non-const, in some specific use cases. As described at <a href="http://www.boost.org/doc/libs/1_37_0/libs/utility/value_init.htm#val_init">http://www.boost.org/doc/libs/1_37_0/libs/utility/value_init.htm#val_init</a> </p> <p> In January 2004, "deep const semantics" still wasn't feasible, apparently due to compiler errors in VC++ and Borland: <em>[boost] value_initialized, deep const, and template instantiation</em> <a class="ext-link" href="http://lists.boost.org/Archives/boost/2004/01/59987.php"><span class="icon">​</span>http://lists.boost.org/Archives/boost/2004/01/59987.php</a> <a class="ext-link" href="http://lists.boost.org/Archives/boost/2004/01/60020.php"><span class="icon">​</span>http://lists.boost.org/Archives/boost/2004/01/60020.php</a> </p> <p> Nowadays I think that things have changed for the better. I just replaced the single conversion operator by overloads for const and non-const in my local copy, and tested for VC++ 2003 (7.1), VC++ 2008 (9.0), and CodeGear 2009 (6.10). And all of them passed the tests! </p> <p> Therefore I'd like to propose fixing the issue, according to the attached patch. Fernando, shall we give it a try? </p> <p> I'm aware that the proposed fix potentially breaks some user code, but I think that those cases are easily fixed, and I think that most Boost users are likely to appreciate logical constness. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/2548 Trac 1.4.3 niels_dekker Fri, 28 Nov 2008 19:26:34 GMT attachment set https://svn.boost.org/trac10/ticket/2548 https://svn.boost.org/trac10/ticket/2548 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">value_initialized_constness.patch</span> </li> </ul> Ticket niels_dekker Fri, 20 Feb 2009 20:24:56 GMT owner, status changed https://svn.boost.org/trac10/ticket/2548#comment:1 https://svn.boost.org/trac10/ticket/2548#comment:1 <ul> <li><strong>owner</strong> changed from <span class="trac-author">Fernando Cacciola</span> to <span class="trac-author">niels_dekker</span> </li> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">assigned</span> </li> </ul> <p> Fernando Cacciola allowed me to fix the issue :-) See also "[boost] [utility] A fix for the const issue of value_initialized", <a class="ext-link" href="http://lists.boost.org/Archives/boost/2009/02/148489.php"><span class="icon">​</span>http://lists.boost.org/Archives/boost/2009/02/148489.php</a> </p> Ticket niels_dekker Sun, 22 Feb 2009 19:10:58 GMT cc set https://svn.boost.org/trac10/ticket/2548#comment:2 https://svn.boost.org/trac10/ticket/2548#comment:2 <ul> <li><strong>cc</strong> <span class="trac-author">niels_address_until_2010-10-10@…</span> added </li> </ul> <p> Committed to the trunk, two days ago: changesets <a class="changeset" href="https://svn.boost.org/trac10/changeset/51355" title="Fixed const issue of value_initialized according to ticket #2548. See ...">[51355]</a> and <a class="changeset" href="https://svn.boost.org/trac10/changeset/51356" title="Updated value_initialized documentation and test following changeset ...">[51356]</a> </p> <p> So far, I haven't seen any regression failure because of these commits, but I'll keep an eye at <a href="http://www.boost.org/development/tests/trunk/developer/utility_.html">http://www.boost.org/development/tests/trunk/developer/utility_.html</a> </p> Ticket niels_dekker Tue, 24 Feb 2009 18:17:34 GMT <link>https://svn.boost.org/trac10/ticket/2548#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/2548#comment:3</guid> <description> <p> Hmmm... My commits (<a class="changeset" href="https://svn.boost.org/trac10/changeset/51355" title="Fixed const issue of value_initialized according to ticket #2548. See ...">[51355]</a> and <a class="changeset" href="https://svn.boost.org/trac10/changeset/51356" title="Updated value_initialized documentation and test following changeset ...">[51356]</a>) have caused a compile time regression failure of Intel Version 9.0 Build 20060222Z (see below). </p> <p> I still have to figure out how to work around this issue. Hopefully the commits don't need to be reverted. Any help is appreciated! </p> <p> <a href="http://www.boost.org/development/tests/trunk/output/Sandia-intel-9-0-boost-bin-v2-libs-utility-test-value_init_test-test-intel-linux-9-0-debug.html">http://www.boost.org/development/tests/trunk/output/Sandia-intel-9-0-boost-bin-v2-libs-utility-test-value_init_test-test-intel-linux-9-0-debug.html</a> says: Compile [2009-02-24 12:19:24 UTC]: fail </p> <blockquote> <p> "/usr/local/intel/cc/9.0-032/bin/icpc" -c -xc++ -O0 -g -Ob0 -w1 -fPIC -DBOOST_ALL_NO_LIB=1 -I".." -c -o "/var/scratch/boost/results/boost/bin.v2/libs/utility/test/value_init_test.test/intel-linux-9.0/debug/value_init_test.o" "../libs/utility/test/../value_init_test.cpp" </p> </blockquote> <p> ../libs/utility/test/../value_init_test.cpp(258): error: more than one operator "==" matches these operands: </p> <blockquote> <p> built-in operator "pointer == pointer" built-in operator "pointer == pointer" operand types are: boost::value_initialized&lt;NonPOD *&gt; == NonPOD *const </p> </blockquote> <blockquote> <p> BOOST_CHECK ( x == z ) ; <sup> </sup></p> <blockquote> <p> detected during instantiation of "bool test(const T &amp;, const T &amp;) [with T=NonPOD *]" </p> </blockquote> </blockquote> <p> ../libs/utility/test/../value_init_test.cpp(265): error: more than one operator "==" matches these operands: </p> <blockquote> <p> built-in operator "pointer == pointer" built-in operator "pointer == pointer" operand types are: const boost::value_initialized&lt;NonPOD *&gt; == NonPOD *const </p> </blockquote> <blockquote> <p> BOOST_CHECK ( x_c == z ) ; <sup> </sup></p> <blockquote> <p> detected during instantiation of "bool test(const T &amp;, const T &amp;) [with T=NonPOD *]" </p> </blockquote> </blockquote> <p> compilation aborted for ../libs/utility/test/../value_init_test.cpp (code 2) </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Daniel James</dc:creator> <pubDate>Sat, 27 Jun 2009 12:20:07 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/2548#comment:4 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/2548#comment:4</guid> <description> <p> This should either be fixed or reverted. If it's a bug with Intel 9 then it would probably be best to use a <code>BOOST_WORKAROUND</code> macro for the compilers which have this bug. And you'll need to update the version number in the documentation, since 1.39 has the old version. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>niels_dekker</dc:creator> <pubDate>Sun, 28 Jun 2009 21:39:15 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/2548#comment:5 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/2548#comment:5</guid> <description> <p> Daniel, thanks for your feedback. Yes, I would still like the issue to be fixed. It's now more than four months after committing the fix to the trunk, <a class="changeset" href="https://svn.boost.org/trac10/changeset/51355" title="Fixed const issue of value_initialized according to ticket #2548. See ...">[51355]</a>, and I haven't heard any compaint. (I did announce the fix at the Boost dev mailing list.) Intel 9 is the only compiler on the regression site that doesn't compile implicit conversions from value_initialized&lt;T&gt; to reference-to-T anymore, because of the fix. It's no problem to Intel 10 and 11, and any other compiler included with the regression tests. </p> <p> There are various possible workarounds for Intel 9: </p> <ol class="loweralpha"><li>Do nothing. Intel 9 users can still retrieve a reference to the value_initialized data by using <code>boost::get</code>, or <code>value_initialized::data()</code> </li><li>Revert the fix, but only for Intel 9 (using BOOST_WORKAROUND). Leave the fix in there for other compilers. </li><li>Offer to Intel 9 users only the const-version of the conversion operator (using BOOST_WORKAROUND) </li><li>Offer to Intel 9 users only the non-const-version of the conversion operator (using BOOST_WORKAROUND) </li></ol><p> I do prefer workaround "d.", which allows Intel 9 users to convert from value_initialized&lt;T&gt; to T&amp;, but protects <code>const value_initialized&lt;T&gt;</code> objects against such a conversion. As attached: intel_9_value_init_conversion-operator.patch Please let me know if you think this patch is fine to you. </p> <p> PS Thanks also for reminding me to update the version number in the documentation! </p> </description> <category>Ticket</category> </item> <item> <dc:creator>niels_dekker</dc:creator> <pubDate>Sun, 28 Jun 2009 21:40:05 GMT</pubDate> <title>attachment set https://svn.boost.org/trac10/ticket/2548 https://svn.boost.org/trac10/ticket/2548 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">intel_9_value_init_conversion-operator.patch</span> </li> </ul> Ticket Daniel James Sun, 28 Jun 2009 22:43:56 GMT <link>https://svn.boost.org/trac10/ticket/2548#comment:6 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/2548#comment:6</guid> <description> <p> I'm really not the person to ask, I'm mainly trying to get some of the 'core' libraries to be consistent on trunk and release in response to some recent mails on the development list. </p> <p> My normal preference would be to preserve the old behaviour for broken compilers (option b, I think) but the old behaviour looks wrong. I don't know why it was written that way so I don't feel qualified to express a preference. So I'm fine with your patch. No one else seems to care so I would suggest that you go ahead with what you think best. You've already asked for feedback on the development list, so I don't think you have to do it again, unless you feel it's necessary. </p> <p> Thanks for sorting this out. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>niels_dekker</dc:creator> <pubDate>Mon, 29 Jun 2009 18:19:27 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/2548#comment:7 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/2548#comment:7</guid> <description> <p> You're welcome, Daniel. </p> <p> I have a problem with "option b", as it would make the behaviour of value_initialized compiler-dependent. So I sticked with "option d", by applying intel_9_value_init_conversion-operator.patch: changeset <a class="changeset" href="https://svn.boost.org/trac10/changeset/54502" title="Worked around Intel 9 specific ambiguity w.r.t. value_initialized ...">[54502]</a>. Hopefully it will lower the number of Intel 9 compile errors from 2 to 1, as the compiler should now be able to accept BOOST_CHECK(x == z). If so, I'll mark the other Intel 9 compile error as an "expected failure", and do a merge to the release branch, when the time is right. </p> <p> PS I also updated the documentation, as you suggested: changeset <a class="changeset" href="https://svn.boost.org/trac10/changeset/54503" title="Updated documentation of value_initialized, according to a remark by ...">[54503]</a> </p> </description> <category>Ticket</category> </item> <item> <dc:creator>niels_dekker</dc:creator> <pubDate>Wed, 01 Jul 2009 09:10:38 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/2548#comment:8 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/2548#comment:8</guid> <description> <p> So I marked the Intel 9 failure: changeset <a class="changeset" href="https://svn.boost.org/trac10/changeset/54560" title="Marked value_init_test failure of Intel 9.0, triggered by trying to ...">[54560]</a> </p> <p> Unfortunately the number of Intel 9 compile errors is not reduced by the workaround I added with changeset <a class="changeset" href="https://svn.boost.org/trac10/changeset/54502" title="Worked around Intel 9 specific ambiguity w.r.t. value_initialized ...">[54502]</a>. Instead, it has gone up from 2 to 33! Before committing the workaround, Intel 9 apparently only failed to convert from value_initialized&lt;T&gt; to T when T was a pointer. While the workaround disables conversion from any <em>const</em> value_initialized&lt;T&gt;, for Intel 9. But it does enable conversion from any non-const value_initialized&lt;T&gt;, including when T is a pointer. So there's clearly a trade-off here. </p> <p> <a href="http://www.boost.org/development/tests/trunk/developer/output/Sandia-intel-9-0-boost-bin-v2-libs-utility-test-value_init_test-test-intel-linux-9-0-debug.html">Sandia-intel-9-0-boost-bin-v2-libs-utility-test-value_init_test-test-intel-linux-9-0-debug.html</a> now reports: </p> <blockquote> <p> Test output: Sandia-intel-9.0 - utility - value_init_test / intel-linux-9.0 </p> </blockquote> <p> Rev 54533 / Tue, 30 Jun 2009 10:33:23 +0000 Report Time: Tue, 30 Jun 2009 20:15:05 +0000 </p> <p> Compile [2009-06-30 12:11:26 UTC]: fail </p> <blockquote> <p> "/usr/local/intel/cc/9.0-032/bin/icpc" -c -xc++ -O0 -g -w1 -Ob0 -fPIC -DBOOST_ALL_NO_LIB=1 -I".." -c -o "/var/scratch/boost/results/boost/bin.v2/libs/utility/test/value_init_test.test/intel-linux-9.0/debug/value_init_test.o" "../libs/utility/test/../value_init_test.cpp" </p> </blockquote> <p> ../libs/utility/test/../value_init_test.cpp(261): error: no operator "==" matches these operands </p> <blockquote> <p> operand types are: const int == const boost::value_initialized&lt;int&gt; </p> </blockquote> <blockquote> <p> BOOST_CHECK ( y == x_c ) ; <sup> </sup></p> <blockquote> <p> detected during instantiation of "bool test(const T &amp;, const T &amp;) [with T=int]" </p> </blockquote> </blockquote> <p> ../libs/utility/test/../value_init_test.cpp(265): error: no operator "==" matches these operands </p> <blockquote> <p> operand types are: const boost::value_initialized&lt;int&gt; == const int </p> </blockquote> <blockquote> <p> BOOST_CHECK ( x_c == z ) ; <sup> </sup></p> <blockquote> <p> detected during instantiation of "bool test(const T &amp;, const T &amp;) [with T=int]" </p> </blockquote> </blockquote> <blockquote> <p> <em>[ snip ]</em> </p> </blockquote> <p> ../libs/utility/test/../value_init_test.cpp(283): error: no operator "==" matches these operands </p> <blockquote> <p> operand types are: const AggregatePODStructWrapper == const boost::value_initialized&lt;const AggregatePODStructWrapper&gt; </p> </blockquote> <blockquote> <p> BOOST_CHECK ( y == cx_c ) ; <sup> </sup></p> <blockquote> <p> detected during instantiation of "bool test(const T &amp;, const T &amp;) [with T=AggregatePODStructWrapper]" </p> </blockquote> </blockquote> <p> compilation aborted for ../libs/utility/test/../value_init_test.cpp (code 2) </p> </description> <category>Ticket</category> </item> <item> <dc:creator>niels_dekker</dc:creator> <pubDate>Sat, 04 Jul 2009 12:22:30 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/2548#comment:9 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/2548#comment:9</guid> <description> <p> I just asked for feedback from Boost users: <em>[Boost-users] [utility] Anyone here using Intel 9.0 compiler + value_initialized?</em>, <a class="ext-link" href="http://lists.boost.org/boost-users/2009/07/49498.php"><span class="icon">​</span>http://lists.boost.org/boost-users/2009/07/49498.php</a> </p> </description> <category>Ticket</category> </item> <item> <dc:creator>niels_dekker</dc:creator> <pubDate>Thu, 09 Jul 2009 08:17:07 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/2548#comment:10 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/2548#comment:10</guid> <description> <p> Fernando Cacciola mailed me that it seems okay to him to just leave implicit conversion from value_initialized&lt;T*&gt; broken for Intel 9.0, instead of having it patched. Which also makes sense to me because it appears a rather rare use case, and it's an old compiler version anyway. So I committed changeset <a class="changeset" href="https://svn.boost.org/trac10/changeset/54832" title="Reverted value_init revision [54502], ...">[54832]</a>, which reverted intel_9_value_init_conversion-operator.patch </p> </description> <category>Ticket</category> </item> <item> <dc:creator>niels_dekker</dc:creator> <pubDate>Sun, 04 Oct 2009 14:19:07 GMT</pubDate> <title>status changed; resolution set https://svn.boost.org/trac10/ticket/2548#comment:11 https://svn.boost.org/trac10/ticket/2548#comment:11 <ul> <li><strong>status</strong> <span class="trac-field-old">assigned</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">fixed</span> </li> </ul> <p> FYI, Yesterday I merged the fix from the trunk to the release branch: changeset <a class="changeset" href="https://svn.boost.org/trac10/changeset/56547" title="Merged value_init from the trunk, including fix of #2548, regarding ...">[56547]</a>. Related merge of value_init_test: Changeset <a class="changeset" href="https://svn.boost.org/trac10/changeset/56543" title="Merged value_init_test from trunk, inc. [51356], anticipating the fix ...">[56543]</a>. I also informed people at the [boost] mailing list: "[boost] [utility] Fix for const issue of value_initialized merged to release", <a class="ext-link" href="http://lists.boost.org/Archives/boost/2009/10/156798.php"><span class="icon">​</span>http://lists.boost.org/Archives/boost/2009/10/156798.php</a> </p> <p> Looks like the fix will be included with Boost 1.41.0 :-) </p> Ticket