From 303d1c55d3670b538425ce63d25230730d498fa1 Mon Sep 17 00:00:00 2001 From: Nathan Sidwell Date: Wed, 2 Jan 2002 12:44:44 +0000 Subject: [PATCH] re PR c++/5213 (ICE on (possibly) illegal code) cp: PR c++/5213 * pt.c (convert_template_argument): Be more careful determining when RECORD_TYPE templates are or are not templates. testsuite: * g++.dg/template/ttp3.C: New test. From-SVN: r48468 --- gcc/cp/ChangeLog | 6 +++++ gcc/cp/pt.c | 40 +++++++++++++++------------- gcc/testsuite/ChangeLog | 2 ++ gcc/testsuite/g++.dg/template/ttp3.C | 26 ++++++++++++++++++ 4 files changed, 56 insertions(+), 18 deletions(-) create mode 100644 gcc/testsuite/g++.dg/template/ttp3.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 3f05cb74a42..145f5bea273 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2002-01-02 Nathan Sidwell + + PR c++/5213 + * pt.c (convert_template_argument): Be more careful determining + when RECORD_TYPE templates are or are not templates. + 2002-01-02 Nathan Sidwell PR c++/775 diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index 139076ecfec..3a0921fefa0 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -1,6 +1,6 @@ /* Handle parameterized types (templates) for GNU C++. Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, - 2001 Free Software Foundation, Inc. + 2001, 2002 Free Software Foundation, Inc. Written by Ken Raeburn (raeburn@cygnus.com) while at Watchmaker Computing. Rewritten by Jason Merrill (jason@cygnus.com). @@ -3291,23 +3291,27 @@ convert_template_argument (parm, arg, args, complain, i, in_decl) requires_type = (TREE_CODE (parm) == TYPE_DECL || requires_tmpl_type); - /* Check if it is a class template. If REQUIRES_TMPL_TYPE is true, - we also accept implicitly created TYPE_DECL as a valid argument. - This is necessary to handle the case where we pass a template name - to a template template parameter in a scope where we've derived from - in instantiation of that template, so the template name refers to that - instantiation. We really ought to handle this better. */ - is_tmpl_type - = ((TREE_CODE (arg) == TEMPLATE_DECL - && TREE_CODE (DECL_TEMPLATE_RESULT (arg)) == TYPE_DECL) - || TREE_CODE (arg) == TEMPLATE_TEMPLATE_PARM - || TREE_CODE (arg) == UNBOUND_CLASS_TEMPLATE - || (TREE_CODE (arg) == RECORD_TYPE - && CLASSTYPE_TEMPLATE_INFO (arg) - && TREE_CODE (TYPE_NAME (arg)) == TYPE_DECL - && DECL_ARTIFICIAL (TYPE_NAME (arg)) - && requires_tmpl_type - && is_base_of_enclosing_class (arg, current_class_type))); + if (TREE_CODE (arg) != RECORD_TYPE) + is_tmpl_type = ((TREE_CODE (arg) == TEMPLATE_DECL + && TREE_CODE (DECL_TEMPLATE_RESULT (arg)) == TYPE_DECL) + || TREE_CODE (arg) == TEMPLATE_TEMPLATE_PARM + || TREE_CODE (arg) == UNBOUND_CLASS_TEMPLATE); + else if (CLASSTYPE_TEMPLATE_INFO (arg) && !CLASSTYPE_USE_TEMPLATE (arg) + && PRIMARY_TEMPLATE_P (CLASSTYPE_TI_TEMPLATE (arg))) + { + if (is_base_of_enclosing_class (arg, current_class_type)) + /* This is a template name used within the scope of the + template. It could be the template, or it could be the + instantiation. Choose whichever makes sense. */ + is_tmpl_type = requires_tmpl_type; + else + is_tmpl_type = 1; + } + else + /* It is a non-template class, or a specialization of a template + class, or a non-template member of a template class. */ + is_tmpl_type = 0; + if (is_tmpl_type && (TREE_CODE (arg) == TEMPLATE_TEMPLATE_PARM || TREE_CODE (arg) == UNBOUND_CLASS_TEMPLATE)) diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 96c503d1fad..fc18102da11 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,5 +1,7 @@ 2002-01-02 Nathan Sidwell + * g++.dg/template/ttp3.C: New test. + * g++.dg/template/friend2.C: New test. * g++.old-deja/g++/brendan/crash8.C: Adjust location of error. diff --git a/gcc/testsuite/g++.dg/template/ttp3.C b/gcc/testsuite/g++.dg/template/ttp3.C new file mode 100644 index 00000000000..05bd44a172e --- /dev/null +++ b/gcc/testsuite/g++.dg/template/ttp3.C @@ -0,0 +1,26 @@ +// { dg-do compile } + +// Copyright (C) 2001 Free Software Foundation, Inc. +// Contributed by Nathan Sidwell 29 Dec 2001 + +// PR 5213. We failed to spot that class List was a template, rather +// than a non-template or specialization + + +template class vector { }; + +class OUTER { + public: + template + class List { }; + + vector data; // { dg-error "type/value mismatch|expected a type|ISO C" "" } +}; + +template +class List { }; // { dg-bogus "previous declaration" "" { xfail *-*-* } } + +// This next line should just do a lookup of 'class List', and then +// get a type/value mismatch. Instead we try and push 'class List' +// into the global namespace and get a redeclaration error. +vector data; // { dg-bogus "`struct List' redeclared|type/value mismatch" "" { xfail *-*-* } } -- 2.30.2