c++/5605: Wrong constructor is called when anonymous object is created in catch block.
Wolfgang Bangerth
bangerth@ticam.utexas.edu
Wed Jan 22 20:56:00 GMT 2003
The following reply was made to PR c++/5605; it has been noted by GNATS.
From: Wolfgang Bangerth <bangerth@ticam.utexas.edu>
To: gcc-bugs@gcc.gnu.org, <gcc-gnats@gcc.gnu.org>
Cc:
Subject: Re: c++/5605: Wrong constructor is called when anonymous object is
created in catch block.
Date: Wed, 22 Jan 2003 14:53:17 -0600 (CST)
This is actually a parser problem:
--------------------
struct A {
A();
A(int) {};
};
main() {
try { throw 666; }
catch (int & e) {
A (e); //***
}
}
-------------------------------
gcc parses the marked line as a declaration of variable e, and tries to
call the default constructor for A, which yields a linker error since
undefined. The submitter claims that this should rather create an unnamed
variable of type A, and run the constructor A::A(int) on it; since
defined, this would link properly.
icc7, by the way, says:
x.cc(9): error: "e" has already been declared in the current scope
A (e);
^
so applies the "this is a named variable" ethic too and spews an
additional error.
I don't know what is right or wrong here.
W.
-------------------------------------------------------------------------
Wolfgang Bangerth email: bangerth@ticam.utexas.edu
www: http://www.ticam.utexas.edu/~bangerth/
More information about the Gcc-prs
mailing list