[exception] exception_ptr missing virtual base parameters
The basic problem I'm experiencing is that getting an exception_ptr results inherited parameters getting lost when virtual inheritance is used. The code below demonstrates a simple example. "bar" is lost in the print. Changing derived_except to be: struct derived_except : base_except { int i; }; will cause the inherited values to be copied into the exception_ptr; however, this has all the standard problems associated that come with not using virtual inheritance. This looks like a bug to me. The C++11 equivalent behaves has expected and inherited values are maintained in the exception_ptr. Any thoughts? michael -------------- boost::exception_ptr version -------------- #include <boost/exception/all.hpp> #include <string> #include <iostream> struct base_except { std::string s; }; struct derived_except : virtual base_except { int i; }; int main() { derived_except e; e.i = 8; e.s = "bar"; boost::exception_ptr ptr = boost::copy_exception(e); try { boost::rethrow_exception(ptr); } catch(derived_except & e) { std::cout << "derived_except: " << e.s << " " << e.i << std::endl; } catch(...) {} return 0; } -------------- c++11 version --------------------- #include <exception> #include <string> #include <iostream> struct base_except { std::string s; }; struct derived_except : virtual base_except { int i; }; int main() { derived_except e; e.i = 8; e.s = "bar"; std::exception_ptr ptr = std::make_exception_ptr(e); try { std::rethrow_exception(ptr); } catch(derived_except & e) { std::cout << "derived_except: " << e.s << " " << e.i << std::endl; } catch(...) {} return 0; } -- Michael Caisse ciere consulting ciere.com
AMDG On 04/10/2013 11:04 PM, Michael Caisse wrote:
The basic problem I'm experiencing is that getting an exception_ptr results inherited parameters getting lost when virtual inheritance is used.
The code below demonstrates a simple example. "bar" is lost in the print. Changing derived_except to be:
struct derived_except : base_except { int i; };
will cause the inherited values to be copied into the exception_ptr; however, this has all the standard problems associated that come with not using virtual inheritance.
This looks like a bug to me. The C++11 equivalent behaves has expected and inherited values are maintained in the exception_ptr. Any thoughts?
The only way to make it work is to restructure clone_impl to use the compiler generated copy constructor. In Christ, Steven Watanabe
AMDG On 04/11/2013 08:17 AM, Steven Watanabe wrote:
On 04/10/2013 11:04 PM, Michael Caisse wrote:
The basic problem I'm experiencing is that getting an exception_ptr results inherited parameters getting lost when virtual inheritance is used.
<snip>
The only way to make it work is to restructure clone_impl to use the compiler generated copy constructor.
...and the templated constructor is not a copy constructor. It's impossible to make this work. In Christ, Steven Watanabe
I apologize for the late reply. It seems like Steven is right, there is no way to make this work. I had two ideas that I tried: 1) I tried to use operator= to copy the virtual bases after the clone_impl constructor has initialized them using their default constructors (unfortunately). This makes the test case Michael posted work, however operator= is not available for types that contain members of reference types. I don't know how common this situation is, but in the boost::exception tests I did have such exceptions (not on purpose) which maybe means it isn't too unusual. 2) My other idea was instead of operator= to call ~T(), then the T copy constructor with placement new over the T sub-object of clone_impl<T>. This duly crashed the test program, which isn't all that surprising but it was worth a try. :) Emil On Thu, Apr 11, 2013 at 8:27 AM, Steven Watanabe <watanabesj@gmail.com>wrote:
AMDG
On 04/11/2013 08:17 AM, Steven Watanabe wrote:
On 04/10/2013 11:04 PM, Michael Caisse wrote:
The basic problem I'm experiencing is that getting an exception_ptr results inherited parameters getting lost when virtual inheritance is used.
<snip>
The only way to make it work is to restructure clone_impl to use the compiler generated copy constructor.
...and the templated constructor is not a copy constructor. It's impossible to make this work.
In Christ, Steven Watanabe
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
participants (3)
-
Emil Dotchevski
-
Michael Caisse
-
Steven Watanabe