This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Re: c++/5605: Wrong constructor is called when anonymous object iscreated in catch block.
- From: Wolfgang Bangerth <bangerth at ticam dot utexas dot edu>
- To: gcc-bugs at gcc dot gnu dot org, <gcc-gnats at gcc dot gnu dot org>
- Date: Wed, 22 Jan 2003 14:53:17 -0600 (CST)
- Subject: Re: c++/5605: Wrong constructor is called when anonymous object iscreated in catch block.
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/