This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[C++ PATCH for 3.4/3.5, committed] Fix PR13797 (missing error_mark_nodechecks)
- From: Kriang Lerdsuwanakij <lerdsuwa at users dot sourceforge dot net>
- To: <gcc-patches at gcc dot gnu dot org>
- Date: Sun, 25 Jan 2004 21:24:23 +0700 (ICT)
- Subject: [C++ PATCH for 3.4/3.5, committed] Fix PR13797 (missing error_mark_nodechecks)
- Reply-to: <lerdsuwa at users dot sourceforge dot net>
Hi
The following patch fixes the PR13797 which is a regression in 3.3/3.4/3.5.
The patch here addresses only 3.4 branch and trunk. The 3.3 version will
be posted in a separated message (due to additional changes required).
The problem here is simply missing checks for error_mark_node after
tsubst'ing class template with invalid nontype template parameter.
Patch is applied to 3.4 and trunk by obvious rule. Tested on
i686-pc-linux-gnu.
--Kriang
2003-01-25 Kriang Lerdsuwanakij <lerdsuwa@users.sourceforge.net>
PR c++/13797
* pt.c (instantiate_class_template): Add an error_mark_node
check.
(tsubst_decl) <TEMPLATE_DECL case>: Likewise.
2003-01-25 Kriang Lerdsuwanakij <lerdsuwa@users.sourceforge.net>
PR c++/13797
* g++.dg/template/nontype4.C: New test.
* g++.dg/template/nontype5.C: Likewise.
diff -cprN gcc-main-save/gcc/cp/pt.c gcc-main-new/gcc/cp/pt.c
*** gcc-main-save/gcc/cp/pt.c Sat Jan 24 18:46:55 2004
--- gcc-main-new/gcc/cp/pt.c Sat Jan 24 18:49:28 2004
*************** instantiate_class_template (tree type)
*** 5387,5393 ****
tree newtag;
newtag = tsubst (tag, args, tf_error, NULL_TREE);
! my_friendly_assert (newtag != error_mark_node, 20010206);
if (TREE_CODE (newtag) != ENUMERAL_TYPE)
{
if (TYPE_LANG_SPECIFIC (tag) && CLASSTYPE_IS_TEMPLATE (tag))
--- 5387,5395 ----
tree newtag;
newtag = tsubst (tag, args, tf_error, NULL_TREE);
! if (newtag == error_mark_node)
! continue;
!
if (TREE_CODE (newtag) != ENUMERAL_TYPE)
{
if (TYPE_LANG_SPECIFIC (tag) && CLASSTYPE_IS_TEMPLATE (tag))
*************** tsubst_decl (tree t, tree args, tree typ
*** 5919,5924 ****
--- 5921,5929 ----
if (TREE_CODE (decl) == TYPE_DECL)
{
tree new_type = tsubst (TREE_TYPE (t), args, complain, in_decl);
+ if (new_type == error_mark_node)
+ return error_mark_node;
+
TREE_TYPE (r) = new_type;
CLASSTYPE_TI_TEMPLATE (new_type) = r;
DECL_TEMPLATE_RESULT (r) = TYPE_MAIN_DECL (new_type);
diff -cprN gcc-main-save/gcc/testsuite/g++.dg/template/nontype4.C gcc-main-new/gcc/testsuite/g++.dg/template/nontype4.C
*** gcc-main-save/gcc/testsuite/g++.dg/template/nontype4.C Thu Jan 1 07:00:00 1970
--- gcc-main-new/gcc/testsuite/g++.dg/template/nontype4.C Fri Jan 23 21:39:38 2004
***************
*** 0 ****
--- 1,14 ----
+ // { dg-do compile }
+
+ // Origin: Ivan Godard <igodard@pacbell.net>
+ // Volker Reichelt <reichelt@gcc.gnu.org>
+
+ // PR c++/13797: ICE invalid nontype template parameter
+
+ template <int> struct A
+ {
+ typedef A<0> B; // { dg-error "not a valid type|conflict" }
+ template <B> struct B {}; // { dg-error "not a valid type|declaration" }
+ };
+
+ A<0> a; // { dg-error "instantiated" }
diff -cprN gcc-main-save/gcc/testsuite/g++.dg/template/nontype5.C gcc-main-new/gcc/testsuite/g++.dg/template/nontype5.C
*** gcc-main-save/gcc/testsuite/g++.dg/template/nontype5.C Thu Jan 1 07:00:00 1970
--- gcc-main-new/gcc/testsuite/g++.dg/template/nontype5.C Fri Jan 23 21:39:43 2004
***************
*** 0 ****
--- 1,14 ----
+ // { dg-do compile }
+
+ // Origin: Ivan Godard <igodard@pacbell.net>
+ // Volker Reichelt <reichelt@gcc.gnu.org>
+
+ // PR c++/13797: ICE invalid nontype template parameter
+
+ template <int> struct A
+ {
+ typedef A<0> B;
+ template <B> struct C {}; // { dg-error "not a valid type" }
+ };
+
+ A<0> a; // { dg-error "instantiated" }