Boost logo

Boost :

From: Hendrik Schober (boost_at_[hidden])
Date: 2001-03-13 06:54:13


Hi,

recently we had to discover, that CW5 as well as CW6 are buggy
when you throw templates as exceptions.

I have an error handling frame work which generates abstract
and concrete exception classes through template instanciation.
While it passed all tests so far on both VC6 and BCB5, when
porting it onto the Mac using CW5 we had to find out, that it
caught one exception type where another was expected. The same
happened when we tried it using CW6.
I created the test case appended below and posted it to a
CW newsgroup. Through discussion with someone from Metrowerks
who hangs out in that group we had to find out that CW has a
bug and treats all templates instances as the same type when
they come thrown as an exception.

My initial reaction to this was, "Don't at least those Boosters
throw templatized exceptions at the compiler?" (I mean, there's
so much template stuff in the boost lib ;^> and, AFAIK, there's
a few of you who do ports to the Mac.)
Well, since I seem to be the first one reporting this bug, it
doesn't look like there's any of these beasts in the boost lib.
Anyway, I just have to ask:

Is there anyone out there who stumbled over this? And is there
any idea out there how one can circumvent it? (Without replacing
the templates by macros, that is.) MacOS is one of our primary
platforms and if I can't get the code do what it is supposed to
do, I'm afraid the exception type generation in my frame work
has to die.
And further: Is there any knowledge out there about pitfalls
with this stuff using gcc? (Which will be the next compiler this
is supposed to be ported.)

TIA,

Schobi

----8<--------8<--------8<--------8<--------8<--------8<----

class AVBase { public: virtual ~AVBase() = 0; };
AVBase::~AVBase() {}

class Implementation : virtual public AVBase {};

template< typename Dummy, typename Base = AVBase >
class TInterface : virtual public Base {};

template< typename Interface >
class TImplementation : virtual public Interface,
                                public Implementation {};

struct Dummy1 {};
typedef TInterface<Dummy1> Interf1;
typedef TImplementation<Interf1> Impl1;

struct Dummy2 {};
typedef TInterface<Dummy2,Interf1> Interf2;
typedef TImplementation<Interf2> Impl2;

bool test_Exception2()
{
  try {
    throw Impl1();
  } catch( Interf2& ) {
    std::cerr << "Exception 'Impl1' erroneously caught as 'Interf2'!\n";
    return false;
  } catch(...) {
    return true;
  }
  std::cerr << "No exception thrown!";
  return false;
}

----8<--------8<--------8<--------8<--------8<--------8<----


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk