Boost C++ Libraries: Ticket #11520: pointer_iserializer requires operator delete(void*, size_t) for classes that have a specific operator new https://svn.boost.org/trac10/ticket/11520 <p> Serialization of pointers to objects, which have a class specific operator new fails if the class only provides the regular (see <a class="ext-link" href="https://github.com/boostorg/serialization/blob/master/include/boost/archive/detail/iserializer.hpp#L236"><span class="icon">​</span>https://github.com/boostorg/serialization/blob/master/include/boost/archive/detail/iserializer.hpp#L236</a>) </p> <p> T::operator delete(void*) </p> <p> by requiring definition of </p> <p> T::operator delete(void*, std::size_t) </p> <p> However, the operator delete with size argument is entirely optional in the C++ standard. The comment in the code says this choice was made because the delete operator with only one argument is a usual deallocator, which the author assumes calls the destructor. This is incorrect in two ways: a) operator delete never calls the destructor (the delete expression calls the destructor and then operator delete to deallocate the storage, see sec. 5.3.5 of the standard) b) operator delete with a size argument is a usual delete operator (non-placement), just like the version with one argument. </p> <p> In fact, it seems that the behaviour may be undefined if both versions of the delete operator are defined (sec. 5.3.5 paragraph 10). </p> <p> I don't know how to test which of the two operators exists, but it seems safer to me to use the one-argument version. My existing code stopped working after upgrading boost, and I do not have access to the class being serialized. I am using an external non-intrusive serialization function. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/11520 Trac 1.4.3 Robert Ramey Mon, 28 Sep 2015 06:05:24 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/11520#comment:1 https://svn.boost.org/trac10/ticket/11520#comment:1 <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> <p> OK - I find you're argument pretty convincing so I'll check the change into the development branch. </p> <p> I'm wondering why the two argument version exists at all. </p> Ticket Robert Ramey Mon, 28 Sep 2015 07:15:15 GMT status changed; resolution deleted https://svn.boost.org/trac10/ticket/11520#comment:2 https://svn.boost.org/trac10/ticket/11520#comment:2 <ul> <li><strong>status</strong> <span class="trac-field-old">closed</span> → <span class="trac-field-new">reopened</span> </li> <li><strong>resolution</strong> <span class="trac-field-deleted">fixed</span> </li> </ul> <p> Damn! </p> <p> I made the change and it failed to compile test_new_operator. </p> <p> So, I'm back to seeing how to figure which operator arguments to call. </p> <p> I notice I made the change 18 months ago and this is the first complaint. i'm not sure what else to do here. There is a way to figure out which function exists - but it's would be pretty complex to implement. If you want to do it (and improve the test) I'll consider adding it in. Google boost check if function exists </p> Ticket Robert Ramey Mon, 28 Sep 2015 22:18:26 GMT <link>https://svn.boost.org/trac10/ticket/11520#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/11520#comment:3</guid> <description> <p> OK - I looked at this some more - I believe the right solution is to use SFINAE to detect which functions are implemented and call the correct one. </p> <p> Unfortunately, this is kind of a pain so it will be some time before I get to it. </p> <p> Feel free to submit a patch </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Robert Ramey</dc:creator> <pubDate>Mon, 05 Oct 2015 16:20:14 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/11520#comment:4 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/11520#comment:4</guid> <description> <p> "I don't know how to test which of the two operators exists, but it seems safer to me to use the one-argument version. My existing code stopped working after upgrading boost, and I do not have access to the class being serialized. I am using an external non-intrusive serialization function." </p> <p> OK - I "fixed" this in that it automatically select the one vs two argument version. However it fails to detect and case where the class has no member function operator delete. So it fixes your problem but leaves one case unfixed. I spend a fair amount of time on this and wasn't able to find a clean way of doing this. I'm sure some smart guy can do it but for now I'm going to declare victory and close this ticket. </p> <p> I also updated the test in order to verify this. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Robert Ramey</dc:creator> <pubDate>Wed, 07 Oct 2015 19:17:02 GMT</pubDate> <title>status changed; resolution set https://svn.boost.org/trac10/ticket/11520#comment:5 https://svn.boost.org/trac10/ticket/11520#comment:5 <ul> <li><strong>status</strong> <span class="trac-field-old">reopened</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">fixed</span> </li> </ul> Ticket fabian.kislat@… Wed, 20 Jan 2016 18:24:45 GMT attachment set https://svn.boost.org/trac10/ticket/11520 https://svn.boost.org/trac10/ticket/11520 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">choose_deleter.cpp</span> </li> </ul> <p> Example, how one might handle all three cases: delete operator with one or two arguments, or no class specific delete at all using SFINAE </p> Ticket kartikmohta@… Sun, 06 Mar 2016 08:03:41 GMT <link>https://svn.boost.org/trac10/ticket/11520#comment:6 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/11520#comment:6</guid> <description> <p> This also fails in the case when a class has both the operators defined. A simple example: </p> <pre class="wiki">#include &lt;boost/archive/text_iarchive.hpp&gt; #include &lt;boost/serialization/export.hpp&gt; class TestClass { public: void* operator new(size_t size) { return ::operator new(size); } void operator delete(void * ptr) { return ::operator delete(ptr); } void operator delete(void *ptr, size_t /*size*/) { return ::operator delete(ptr); } template &lt;class Archive&gt; void serialize(Archive &amp; /* ar */, const unsigned int /* version */) { } }; BOOST_CLASS_EXPORT_IMPLEMENT(TestClass); int main() { return 0; } </pre><p> Don't have a solution for this, but just making a note here in case someone can solve the issue. </p> </description> <category>Ticket</category> </item> <item> <author>kartikmohta@…</author> <pubDate>Sun, 06 Mar 2016 08:04:42 GMT</pubDate> <title>status changed; resolution deleted https://svn.boost.org/trac10/ticket/11520#comment:7 https://svn.boost.org/trac10/ticket/11520#comment:7 <ul> <li><strong>status</strong> <span class="trac-field-old">closed</span> → <span class="trac-field-new">reopened</span> </li> <li><strong>resolution</strong> <span class="trac-field-deleted">fixed</span> </li> </ul> Ticket