This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.
Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|
Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |
Mike Stump
Here is the list of discrepancies that I have found so far in
the way function-try-blocks are handled by G++.
I used the following simple program in various
forms
==================================================== #include <iostream> #include <stdexcept> using namespace std;
static int count = 0;
struct T {
int i; T() :i(++count) { cout << "Making T #" << i << endl; } T(const T& obj) :i(++count) { cout << "Copying T #" << obj.i << " to T #" << i << endl; } ~T() { cout << "Destroying T #" << i << endl; } }; int dummyInit(bool f) { if (f) throw logic_error("Constructor exception"); return 0; } struct Dummy {
T tmp; int i; Dummy(T t, bool f); ~Dummy(); }; Dummy::Dummy(T t, bool f)
try : tmp(t), i(dummyInit(f)) { cout << "Ctor: f = " << f << endl; } catch (logic_error& err) { cout << "Ctor catch(logic_error): what = " << err.what() << endl; cout << "Constructor was passed T #" << t.i << ", f = " << f << endl; return; file://###1 } Dummy::~Dummy()
try { cout << "Dummy::dtor" << endl; throw std::logic_error("Destructor exception"); } catch (logic_error& err) { cout << "Dtor catch(logic_error): what = " << err.what() << endl; } int
main() { cout << "Declaring a Dummy" << endl; try { T tmp; Dummy obj(tmp, true); cout << "main: 'obj' construction complete" << endl; } catch (logic_error& err) { cout << "main catch(logic_error): what = " << err.what() << endl; return -1; } catch (...) { cout << "main catch(...)" << endl; return -1; } return 0; } ================================================================ A. The Standard says [15.3/11: The fully constructed base
classes and members of an object shall be destroyed before entering the handler
of a function-try-block for the constructor or destructor of that
object.]
The output of this program shows that the member 'tmp' is
constructed before the exception, but not destroyed before entering the handler
for either the constructor's or the destructor's
function-try-block.
B. The Standard says [15.3/15: If a return statement appears
in the handler of a function-try-block of a constructor, the program is
ill-formed]
I assume that the program above should issue a diagnostic for
the return statement at ###1
C. The Standard says [15.3/16: The exception being handled is
rethrown if control reaches the end of a handler of the function-try-block of a
constructor or a destructor.]
If we remove the 'return' at ###1, the program demonstrates
that the exception is not rethrown at the end of the constructor's
function-try-block. Nor is it rethrown at the end of the destructor's
function-try-block. The behavior in both cases is as if the handler of the
function-try-block returned.
This is all I have discovered so far. I will be doing some
more testing in the future. If I haven't mentioned it before, I think it is
really great that G++ supports function-try-blocks. I intend to be using them in
the near future.
Jack Reeves
|
Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|
Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |