Bug 5605 - name of caught object redeclared (c.f. 3.3.2/3)
Summary: name of caught object redeclared (c.f. 3.3.2/3)
Status: RESOLVED DUPLICATE of bug 31952
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 3.0.3
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
Keywords: accepts-invalid
Depends on: 2288
  Show dependency treegraph
Reported: 2002-02-06 00:26 UTC by cs
Modified: 2012-08-20 10:40 UTC (History)
6 users (show)

See Also:
Known to work:
Known to fail:
Last reconfirmed: 2005-12-11 21:46:26

test.cpp (152 bytes, application/octet-stream)
2003-05-21 15:16 UTC, cs

Note You need to log in before you can comment on or make changes to this bug.
Description cs 2002-02-06 00:26:00 UTC
When executing a code like:

try {
   // .....
} catch (SomeException &e) {
will be called SomeClass::SomeClass() constructor instead of
SomeClass(SomeException) or something like.

at least 2.95.3 and 3.0.3

I'm sure it doesn't matter, at least on FreeBSD 4.3, 4.5 and RedHat 7.2 on i386.

Just compile and run file attached. it outputs 
instead of 
Comment 1 cs 2002-02-06 00:26:00 UTC
Don't know
Comment 2 Nathan Sidwell 2002-09-15 11:58:05 UTC
State-Changed-From-To: open->analyzed
State-Changed-Why: confirmed. Weird.
Comment 3 Wolfgang Bangerth 2003-01-22 14:53:17 UTC
From: Wolfgang Bangerth <bangerth@ticam.utexas.edu>
To: gcc-bugs@gcc.gnu.org, <gcc-gnats@gcc.gnu.org>
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(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.
 Wolfgang Bangerth             email:            bangerth@ticam.utexas.edu
                               www: http://www.ticam.utexas.edu/~bangerth/
Comment 4 Wolfgang Bangerth 2003-05-08 22:46:54 UTC
Responsible-Changed-From-To: unassigned->nathan
Responsible-Changed-Why: Nathan, another case where I'd like the opinion of a language
Comment 5 Nathan Sidwell 2003-05-10 14:36:02 UTC
Responsible-Changed-From-To: nathan->unassigned
Responsible-Changed-Why: icc is correct.
    1) 'A (e)' is a declaration of variable 'e' -- the grammar is ambiguous and the std rule in favour of a declaration rather than an expression
    2) the scope of this new 'e' is the same as that of the caught object named 'e'. So an error should be issues. [3.3.2]/3 says so
Comment 6 Andrew Pinski 2005-09-04 18:48:51 UTC
This is similar to PR 2288.
Comment 7 Paolo Carlini 2012-08-20 10:40:59 UTC
Per Comment #5 this is identical to Comment #2 of PR31952.

*** This bug has been marked as a duplicate of bug 31952 ***