This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
c++/7239: g++ rejects pointer to own class type in throw statement
- From: mayer at tux dot org
- To: gcc-gnats at gcc dot gnu dot org
- Date: Mon, 8 Jul 2002 18:28:05 -0700 (PDT)
- Subject: c++/7239: g++ rejects pointer to own class type in throw statement
- Reply-to: mayer at tux dot org
>Number: 7239
>Category: c++
>Synopsis: g++ rejects pointer to own class type in throw statement
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: unassigned
>State: open
>Class: rejects-legal
>Submitter-Id: net
>Arrival-Date: Mon Jul 08 18:36:01 PDT 2002
>Closed-Date:
>Last-Modified:
>Originator:
>Release: 3.0.2
>Organization:
tux.org
>Environment:
System: SunOS hydra 5.6 Generic_105181-16 sun4u sparc SUNW,Ultra-2
Architecture: sun4
host: sparc-sun-solaris2.6
build: sparc-sun-solaris2.6
target: sparc-sun-solaris2.6
configured with: ../gcc/configure --prefix=/work/hyd01/td/sw/gcc_3_0_2_release --disable-nls --disable-threads --disable-shared --enable-languages=c,c++,f77,objc
>Description:
G++ does not compile any class that has a pointer to its own class type as an
exception type in the throw specification of a member function.
>How-To-Repeat:
Assume the file bug.cc contains the following three lines:
struct X {
void f() throw (X*) { throw this;}
};
Then the command "g++ -c bug.cc" creates the error message
bug.cc:2: invalid use of undefined type `struct X'
bug.cc:1: forward declaration of `struct X'
"g++ -c -E bug.cc" reports:
# 1 "bug.cc"
struct X {
void f() throw (X*) { throw this;}
};
>Fix:
Do not have one. Work-around: Use a wrapper class, as in:
struct X;
struct Y {
Y(const X * x) : xp(x) {}
const X * xp;
};
struct X {
void f() throw (Y) { throw Y(this);}
};
This compiles fine.
>Release-Note:
>Audit-Trail:
>Unformatted: