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
URL:
Keywords: accepts-invalid
Depends on: 2288
Blocks:
  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:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2005-12-11 21:46:26


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

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) {
     SomeClass(e);
}
will be called SomeClass::SomeClass() constructor instead of
SomeClass(SomeException) or something like.

Release:
at least 2.95.3 and 3.0.3

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

How-To-Repeat:
Just compile and run file attached. it outputs 
A::A()
instead of 
A::A(int)
Comment 1 cs 2002-02-06 00:26:00 UTC
Fix:
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>
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/
 
 
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
    lawyer.
    
    Thanks
      W.
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 ***