> > > * whenever an exception object was created on a stack and then thrown
> > > (thus causing the dtor for that object to fire!), it was replaced
> > > with a STATIC exception
> >
> > The whole thing looks like a solution desperately searching for a
> > problem. The reasoning for this patch contradicts Stroustrup, who
> > has several examples of what we are doing in "The C++ programming
> > language". Maybe it's only because I'm using an older copy (2nd ed.),
> > but he writes (p. 602, "r.15.2 Throwing an Exception"):
> >
> > "A throw-expression initializes a temporary object of the static
> > type of the operand of throw and uses that temporary to initialize
> > the appropriately-typed variable named in the handler."
> >
> > The throw expression cares for the thrown class to be available
> > until it reached the handler. No need to spread ugly static
> > variables everywhere. Our code looks right for me as it is. But
I've created the following C++ snippet:
-- CUT HERE --
#include <exception>
#include <iostream>
#include <string>
using namespace std;
struct E : exception {
E() : _msg("DEFAULT") { cout << "E::E()" << endl; }
E(const char* s) : _msg(s) {
cout << "E::E(const char*" << s << ")" << endl; }
E(const E& e) : _msg(e._msg + "(clone)") {
cout << "E::E(const E&" << e._msg << ")" << endl; }
E& operator=(const E& e) {
cout << "E::operator=(" << e._msg << ") assigned over " << _msg <<
endl;
_msg = e._msg + "(assigned)";
return *this;
}
virtual ~E() throw() { cout << "E::~E() " << _msg << endl; }
const char* what() const throw() { _msg.c_str(); }
string _msg;
};
void foo(int i) throw(exception&)
{
cout << "foo entering" << endl;
E unused("xUNUSED");
switch (i) {
case 0:
break;
case 1:
throw E("x1");
case 2: {
E weird("x2");
throw weird;
}
}
cout << "foo exiting" << endl;
}
int main()
{
for (int i = 0; i < 3; i++) {
try {
foo(i);
}
catch (E& e) {
cout << "Caught " << e.what() << endl;
}
}
return 0;
}
-- CUT HERE --
and gcc C++ compiler version 3.3.5 (Debian 1:3.3.5-13) has this to
say when compiling it with default flags (fully confirming what
you say -- you can throw either tmp variables, or automatic ones,
created inside a frame to be unwound, and the objects won't be
destroyed until caught):
foo entering
E::E(const char*xUNUSED)
foo exiting
E::~E() xUNUSED
foo entering
E::E(const char*xUNUSED)
E::E(const char*x1)
E::~E() xUNUSED
Caught x1
E::~E() x1
foo entering
E::E(const char*xUNUSED)
E::E(const char*x2)
E::E(const E&x2)
E::~E() x2
E::~E() xUNUSED
Caught x2(clone)
E::~E() x2(clone)
If anybody has access to a suspicious compiler that's critical for their
platform's flightgear development, please do this test and check that
1) no exception is caught before its dtor is called
2) the amount of ctor calls equals the amount of dtor calls
3) no crash occurs
Vassilii
_______________________________________________
Flightgear-devel mailing list
[email protected]
http://mail.flightgear.org/mailman/listinfo/flightgear-devel
2f585eeea02e2c79d7b1d8c4963bae2d