J
Johannes Schaub (litb)
I tried to force programmers of a derived class to explicitly define a
constructor (just for fun). This is what i came up with:
struct Viral {
struct Dose { };
protected:
~Viral() throw (Dose) { }
};
struct Base : virtual Viral {
virtual ~Base() throw() { }
};
struct Derived : Base { };
It's an illegal program because Derived::~Derived calls ~Viral, so it
includes (Dose) in its exception spec, but as it overrides ~Base, it will
have a looser exception spec and is this illegal. The user explicitly needs
to overrideit
struct Derived : Base { ~Derived() throw() { } }; // OK
Clang rejects the code with the implicitly defined destructor, but GCC and
comeau online accept it, which surprises me.
Are clang and me right, or are we wrong and the other two are right?
constructor (just for fun). This is what i came up with:
struct Viral {
struct Dose { };
protected:
~Viral() throw (Dose) { }
};
struct Base : virtual Viral {
virtual ~Base() throw() { }
};
struct Derived : Base { };
It's an illegal program because Derived::~Derived calls ~Viral, so it
includes (Dose) in its exception spec, but as it overrides ~Base, it will
have a looser exception spec and is this illegal. The user explicitly needs
to overrideit
struct Derived : Base { ~Derived() throw() { } }; // OK
Clang rejects the code with the implicitly defined destructor, but GCC and
comeau online accept it, which surprises me.
Are clang and me right, or are we wrong and the other two are right?