c++ - gcc exception specification of default destructor -


class {     public:     virtual ~a()     {     } };  class b : virtual public {     public:     ~b() throw()     {} };  class c : public b { };  int main(int argc, char * argv []) { return 0; } 

that code gives following error:

error: looser throw specifier ‘virtual c::~c()’ error:   overriding ‘virtual b::~b() throw ()’ 

on debian testing ( gcc (debian 4.6.0-10) 4.6.1 20110526 (prerelease) ) compiles without errors on previous gcc versions ( 4.5 on debian system again).

how exception specification affect virtual destructor overriding? according answer compiler supposed create default constructor matching throw declaration of base class. not happens on new gcc. has changed, correct compiler behavior , there easy solution problem other manually adding empty destructors in derived classes ( compiler flag example).

i presume in real code either ~a() or ~b() declared virtual? (the error message complaining virtual destructor, in code written none of destructors virtual.)

i believe virtual inheritance triggering problem. c's (implicitly defined) destructor required first call ~b() , then, because c most-derived class, call ~a(). (12.4/6)

the generated exception specification ~c() required allow exception propagate, because directly calls ~a() has no exception specification. (15.4/13)

and triggers error - can't override virtual function throw() specification (b's destructor) version may throw. (15.4/3)

the solution put throw() on a's destructor. (if can't that, why doing on b's?)

the error wouldn't happen without virtual inheritance - because c's destructor call b's destructor. (b's destructor still call a's - , you're still skating on thin ice, because if a's destructor throws you're going straight terminate().)


Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -