[C++ PATCH] Fix PR6716, a regression
Kriang Lerdsuwanakij
lerdsuwa@users.sourceforge.net
Sat May 25 09:24:00 GMT 2002
Hi
The following patch fixes the PR6716 which is a regression from GCC 3.0.
Currently GCC ICE's on illegal code containing incomplete class deep
inside some complex class structure. Rather than relying on the rest
of template instantiation code to deal with incomplete types, which is
prone to error. The patch make sure that error is detect and the
instantiation is stopped and return with error immediately.
Bootstrapped and tested with no regressions. Ok to commit to 3.1 branch
and main trunk?
--Kriang
2002-05-25 Kriang Lerdsuwanakij <lerdsuwa@users.sourceforge.net>
PR c++/6716
* pt.c (instantiate_class_template): Return immediately if one
of the fields is an incomplete type.
diff -cprN gcc-main-save/gcc/cp/pt.c gcc-main-new/gcc/cp/pt.c
*** gcc-main-save/gcc/cp/pt.c Thu May 23 22:46:29 2002
--- gcc-main-new/gcc/cp/pt.c Sat May 25 18:59:50 2002
*************** instantiate_class_template (type)
*** 5323,5329 ****
if (TREE_CODE (t) == FIELD_DECL)
{
TREE_TYPE (t) = complete_type (TREE_TYPE (t));
! require_complete_type (t);
}
/* Set the file and line number information to whatever is given for
--- 5323,5330 ----
if (TREE_CODE (t) == FIELD_DECL)
{
TREE_TYPE (t) = complete_type (TREE_TYPE (t));
! if (require_complete_type (t) == error_mark_node)
! return error_mark_node;
}
/* Set the file and line number information to whatever is given for
diff -cprN gcc-main-save/gcc/testsuite/g++.dg/template/instantiate1.C gcc-main-new/gcc/testsuite/g++.dg/template/instantiate1.C
*** gcc-main-save/gcc/testsuite/g++.dg/template/instantiate1.C Thu Jan 1 07:00:00 1970
--- gcc-main-new/gcc/testsuite/g++.dg/template/instantiate1.C Sat May 25 21:00:40 2002
***************
*** 0 ****
--- 1,21 ----
+ // { dg-do compile }
+ // Origin:
+
+ // PR c++/6716
+ // ICE in complex class structure when components are incomplete
+
+ template <class T> struct X { // { dg-error "type|declaration" }
+ T t;
+ };
+
+ template <class T> struct Y { // { dg-error "instantiated|declaration" }
+ X<T> x;
+ };
+
+ template <class T> struct Z { // { dg-error "instantiated|declaration" }
+ Y<Z<T> > y;
+ };
+
+ struct ZZ : Z<int>
+ { // { dg-error "instantiated" }
+ };
More information about the Gcc-patches
mailing list