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]
Other format: [Raw text]

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/



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]