Boost logo

Boost Users :

Subject: [Boost-users] [exception] exception_ptr missing virtual base parameters
From: Michael Caisse (mcaisse-lists_at_[hidden])
Date: 2013-04-11 02:04:35


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

Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net