Boost C++ Libraries: Ticket #8268: basic_hold_any missing assignment operator https://svn.boost.org/trac10/ticket/8268 <p> Self contatined repro: </p> <p> struct Big { </p> <blockquote> <p> int x[ 4 ]; </p> </blockquote> <p> }; (big enough to prevent the small optimisation in hold_any) </p> <p> { </p> <blockquote> <p> boost::spirit::hold_any sourceAny = boost::spirit::hold_any( Big() ); </p> </blockquote> <blockquote> <p> boost::spirit::hold_any copyInto; </p> </blockquote> <p> </p> <blockquote> <p> copyInto = sourceAny; </p> </blockquote> <blockquote> <p> (calls a compiler generated assignment operator which copies the address of the memory allocated in sourceAny) </p> </blockquote> <p> } <em> CRASH: double deletion of the heap allocated Big held in sourceAny as both copyInto </em> and sourceAny go out of scope </p> <p> The problem is that the assignment operator provided in basic_hold_any doesn't suppress the compiler generated one because it is a template function, and the compiler generator one only does a shallow copy. </p> <p> The relevant section in the C++ standard is N3485 §12.18: </p> <p> "A user-declared copy assignment operator X::operator= is a non-static non-template member function of class X with exactly one parameter of type X, X&amp;, const X&amp;, volatile X&amp; or const volatile X&amp;. (121)" </p> <p> "(121) Because a template assignment operator or an assignment operator taking an rvalue reference parameter is never a copy assignment operator, the presence of such an assignment operator does not suppress the implicit declaration of a copy assignment operator. Such assignment operators participate in overload resolution with other assignment operators, including copy assignment operators, and, if selected, will be used to assign an object." </p> <p> To fix this issue, simply add the non-template assignment constructor to basic_hold_any: </p> <p> <em> assignment operator basic_hold_any&amp; operator=(basic_hold_any const&amp; x) { </em></p> <blockquote> <p> return assign(x); </p> </blockquote> <p> } </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/8268 Trac 1.4.3 Joel de Guzman Sat, 09 Mar 2013 04:27:21 GMT <link>https://svn.boost.org/trac10/ticket/8268#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/8268#comment:1</guid> <description> <p> Indeed. Please provide a patch making sure all tests pass. Thanks! </p> </description> <category>Ticket</category> </item> <item> <author>Matthew South <msouth@…></author> <pubDate>Sat, 09 Mar 2013 18:21:04 GMT</pubDate> <title>attachment set https://svn.boost.org/trac10/ticket/8268 https://svn.boost.org/trac10/ticket/8268 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">msouth_ticket8268.patch</span> </li> </ul> <p> Patch created in /trunk/boost/spirit/home/support/detail/ as described in bug report. </p> Ticket Matthew South <msouth@…> Sat, 09 Mar 2013 18:36:35 GMT <link>https://svn.boost.org/trac10/ticket/8268#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/8268#comment:2</guid> <description> <p> I've attached a patch but I've not run the tests (other than my own) as my current environment is not setup to run them (I'm not a boost developer). </p> </description> <category>Ticket</category> </item> <item> <author>stephan.kaiser@…</author> <pubDate>Thu, 06 Jun 2013 13:19:01 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/8268#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/8268#comment:3</guid> <description> <p> I ran into the same issue. Thanks for the fix. </p> <p> When will this reach the official boost release? </p> <p> I'm not a boost developer and don't know what is required to make "sure all tests pass". I take it this is what is required: "Otherwise, create a temporary branch in subversion, make your changes there, and ask the library author(s)/maintainer(s) to review them; if approve the new code, either you or they can integrate the fixes into the main trunk." </p> <p> Is that right? </p> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Thu, 17 Mar 2016 15:03:44 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/8268#comment:4 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/8268#comment:4</guid> <description> <p> Any news? </p> </description> <category>Ticket</category> </item> <item> <author>Nikita Kniazev <nok.raven@…></author> <pubDate>Sun, 18 Feb 2018 17:42:33 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/8268#comment:5 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/8268#comment:5</guid> <description> <p> Have been fixed for C++11 in <a class="ext-link" href="https://github.com/boostorg/spirit/pull/36"><span class="icon">​</span>https://github.com/boostorg/spirit/pull/36</a>. Fixed completely in <a class="ext-link" href="https://github.com/boostorg/spirit/pull/361"><span class="icon">​</span>https://github.com/boostorg/spirit/pull/361</a>. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Joel de Guzman</dc:creator> <pubDate>Mon, 19 Feb 2018 23:16:42 GMT</pubDate> <title>status changed; resolution set https://svn.boost.org/trac10/ticket/8268#comment:6 https://svn.boost.org/trac10/ticket/8268#comment:6 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">fixed</span> </li> </ul> Ticket