This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[C++ PATCH for 3.3] Fix PR13797 (missing error_mark_node check)
- 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:26:09 +0700 (ICT)
- Subject: [C++ PATCH for 3.3] Fix PR13797 (missing error_mark_node check)
- Reply-to: <lerdsuwa at users dot sourceforge dot net>
Hi
This is the 3.3 version of patch for PR13797 regression. Fixing PR13797
requires an additional error_mark_node checking patch from the main trunk:
http://gcc.gnu.org/ml/gcc-patches/2003-05/msg00757.html
The expected error for the testcase is different in 3.3 branch however.
So I put together all the required changes here. Tested on i686-pc-linux-gnu.
Ok for 3.3 branch?
--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.
Backport from mainline
2003-05-09 Kriang Lerdsuwanakij <lerdsuwa@users.sourceforge.net>
PR c++/10555, c++/10576
* pt.c (lookup_template_class): Handle class template with
multiple levels of parameters when one of the levels contain
errors.
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.
PR c++/10555, c++/10576
* g++.dg/template/memclass1.C: New test.
diff -cprN gcc-33-save/gcc/cp/pt.c gcc-33-new/gcc/cp/pt.c
*** gcc-33-save/gcc/cp/pt.c Fri Jan 23 22:21:34 2004
--- gcc-33-new/gcc/cp/pt.c Sat Jan 24 23:00:44 2004
*************** lookup_template_class (d1, arglist, in_d
*** 4255,4260 ****
--- 4255,4269 ----
tree a = coerce_template_parms (TREE_VALUE (t),
arglist, template,
complain, /*require_all_args=*/1);
+
+ /* Don't process further if one of the levels fails. */
+ if (a == error_mark_node)
+ {
+ /* Restore the ARGLIST to its full size. */
+ TREE_VEC_LENGTH (arglist) = saved_depth;
+ POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, error_mark_node);
+ }
+
SET_TMPL_ARGS_LEVEL (bound_args, i, a);
/* We temporarily reduce the length of the ARGLIST so
*************** instantiate_class_template (type)
*** 5462,5468 ****
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))
--- 5471,5479 ----
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 (t, args, type, complain)
*** 6001,6006 ****
--- 6012,6020 ----
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-33-save/gcc/testsuite/g++.dg/template/memclass1.C gcc-33-new/gcc/testsuite/g++.dg/template/memclass1.C
*** gcc-33-save/gcc/testsuite/g++.dg/template/memclass1.C Thu Jan 1 07:00:00 1970
--- gcc-33-new/gcc/testsuite/g++.dg/template/memclass1.C Sat Jan 24 23:07:19 2004
***************
*** 0 ****
--- 1,18 ----
+ // { dg-do compile }
+
+ // Origin: Volker Reichelt <reichelt@igpm.rwth-aachen.de>
+
+ // PR c++/10555: ICE for member class template when one of the
+ // template argument levels contains errors.
+
+ template <typename> struct A
+ {
+ template <typename> struct B;
+ };
+
+ template <typename T> struct C
+ {
+ typedef typename A<T>::template B<U> X; // { dg-error "mismatch|expected" }
+ };
+
+ C<void> c; // { dg-error "instantiated" }
diff -cprN gcc-33-save/gcc/testsuite/g++.dg/template/nontype4.C gcc-33-new/gcc/testsuite/g++.dg/template/nontype4.C
*** gcc-33-save/gcc/testsuite/g++.dg/template/nontype4.C Thu Jan 1 07:00:00 1970
--- gcc-33-new/gcc/testsuite/g++.dg/template/nontype4.C Sat Jan 24 22:59:27 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-33-save/gcc/testsuite/g++.dg/template/nontype5.C gcc-33-new/gcc/testsuite/g++.dg/template/nontype5.C
*** gcc-33-save/gcc/testsuite/g++.dg/template/nontype5.C Thu Jan 1 07:00:00 1970
--- gcc-33-new/gcc/testsuite/g++.dg/template/nontype5.C Sat Jan 24 22:59:27 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" }