This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[patch] Fix PR c++/23191, ICE on invalid exception specification intemplate
- From: Volker Reichelt <reichelt at igpm dot rwth-aachen dot de>
- To: gcc-patches at gcc dot gnu dot org
- Date: Thu, 04 Aug 2005 22:41:30 +0200 (CEST)
- Subject: [patch] Fix PR c++/23191, ICE on invalid exception specification intemplate
Consider the following code snippet:
template<typename T> struct A
{
void foo() throw(typename T::X);
};
A<void> a;
When instantiating A<void> the compiler has to substitute T with
void in the declaration of foo. This is handled by calling
tsubst_exception_specification from tsubst. Because void::X is invalid,
tsubst_exception_specification correctly returns an error_mark_node.
However, the compiler fails to check for the error_mark_node and calls
build_exception_variant instead. Because of the error_mark_node this
results in an ICE.
The attached patch fixes the problem by adding a check for error_mark_node
and adds the above testcase.
Bootstrapped and regtested on i686-pc-linux-gnu.
Ok for mainline and 4.0 branch (since this is a regression)?
Regards,
Volker
2005-08-04 Volker Reichelt <reichelt@igpm.rwth-aachen.de>
PR c++/23191
* pt.c (tsubst) <case METHOD_TYPE>: Check for error_mark_node
before calling build_exception_variant.
===================================================================
--- gcc/gcc/cp/pt.c 12 Jul 2005 16:07:34 -0000 1.1015
+++ gcc/gcc/cp/pt.c 4 Aug 2005 00:17:47 -0000
@@ -7316,6 +7316,8 @@ tsubst (tree t, tree args, tsubst_flags_
/* Substitute the exception specification. */
specs = tsubst_exception_specification (t, args, complain,
in_decl);
+ if (specs == error_mark_node)
+ return error_mark_node;
if (specs)
fntype = build_exception_variant (fntype, specs);
return fntype;
===================================================================
2005-08-04 Volker Reichelt <reichelt@igpm.rwth-aachen.de>
PR c++/23191
* g++.dg/template/eh2.C: New test.
===================================================================
--- gcc/gcc/testsuite/g++.dg/template/eh2.C 2003-09-23 19:59:22.000000000 +0200
+++ gcc/gcc/testsuite/g++.dg/template/eh2.C 2005-08-04 02:26:26.000000000 +0200
@@ -0,0 +1,10 @@
+// PR c++/23191
+// Origin: Volker Reichelt <reichelt@igpm.rwth-aachen.de>
+// { dg-do compile }
+
+template<typename T> struct A
+{
+ void foo() throw(typename T::X); // { dg-error "not a class" }
+};
+
+A<void> a; // { dg-error "instantiated" }
===================================================================