This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[C++ PATCH, committed] Fix ICE on illegal template argument (PR10555, 10576)
- From: Kriang Lerdsuwanakij <lerdsuwa at users dot sourceforge dot net>
- To: <gcc-patches at gcc dot gnu dot org>
- Date: Fri, 9 May 2003 22:20:45 +0700 (ICT)
- Subject: [C++ PATCH, committed] Fix ICE on illegal template argument (PR10555, 10576)
- Reply-to: <lerdsuwa at users dot sourceforge dot net>
Hi
The following patch fixes a bug in lookup_template_class when dealing
with illegal code. If the class template has multiple levels of template
parameters and one of the level fails with errors, ERROR_MARK_NODE is
not detected. So it proceeds building TREE_VEC of TREE_VEC's containing
the ERROR_MARK_NODE. This confuses later part of compilation. The
patch changes that by returning ERROR_MARK_NODE immediately rather that
wrapping it inside TREE_VEC.
Tested on i686-pc-linux-gnu. Committed to trunk as obvious.
--Kriang
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-05-09 Kriang Lerdsuwanakij <lerdsuwa@users.sourceforge.net>
PR c++/10555, c++/10576
* g++.dg/template/memclass1.C: New test.
diff -cprN gcc-main-save/gcc/cp/pt.c gcc-main-new/gcc/cp/pt.c
*** gcc-main-save/gcc/cp/pt.c Sat May 3 18:55:25 2003
--- gcc-main-new/gcc/cp/pt.c Fri May 9 21:57:13 2003
*************** lookup_template_class (d1, arglist, in_d
*** 4251,4256 ****
--- 4251,4265 ----
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
diff -cprN gcc-main-save/gcc/testsuite/g++.dg/template/memclass1.C gcc-main-new/gcc/testsuite/g++.dg/template/memclass1.C
*** gcc-main-save/gcc/testsuite/g++.dg/template/memclass1.C Thu Jan 1 07:00:00 1970
--- gcc-main-new/gcc/testsuite/g++.dg/template/memclass1.C Tue May 6 23:11:14 2003
***************
*** 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 "declared|invalid" }
+ };
+
+ C<void> c; // { dg-error "instantiated" }