Commit 303d1c55 by Nathan Sidwell Committed by Nathan Sidwell

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
parent f53d0ff1
2002-01-02 Nathan Sidwell <nathan@codesourcery.com> 2002-01-02 Nathan Sidwell <nathan@codesourcery.com>
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 <nathan@codesourcery.com>
PR c++/775 PR c++/775
* cp-tree.h (handle_class_head): Adjust prototype. * cp-tree.h (handle_class_head): Adjust prototype.
* decl2.c (handle_class_head): Add DEFN_P and NEW_TYPE_P * decl2.c (handle_class_head): Add DEFN_P and NEW_TYPE_P
......
/* Handle parameterized types (templates) for GNU C++. /* Handle parameterized types (templates) for GNU C++.
Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 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. Written by Ken Raeburn (raeburn@cygnus.com) while at Watchmaker Computing.
Rewritten by Jason Merrill (jason@cygnus.com). Rewritten by Jason Merrill (jason@cygnus.com).
...@@ -3291,23 +3291,27 @@ convert_template_argument (parm, arg, args, complain, i, in_decl) ...@@ -3291,23 +3291,27 @@ convert_template_argument (parm, arg, args, complain, i, in_decl)
requires_type = (TREE_CODE (parm) == TYPE_DECL requires_type = (TREE_CODE (parm) == TYPE_DECL
|| requires_tmpl_type); || requires_tmpl_type);
/* Check if it is a class template. If REQUIRES_TMPL_TYPE is true, if (TREE_CODE (arg) != RECORD_TYPE)
we also accept implicitly created TYPE_DECL as a valid argument. is_tmpl_type = ((TREE_CODE (arg) == TEMPLATE_DECL
This is necessary to handle the case where we pass a template name && TREE_CODE (DECL_TEMPLATE_RESULT (arg)) == TYPE_DECL)
to a template template parameter in a scope where we've derived from || TREE_CODE (arg) == TEMPLATE_TEMPLATE_PARM
in instantiation of that template, so the template name refers to that || TREE_CODE (arg) == UNBOUND_CLASS_TEMPLATE);
instantiation. We really ought to handle this better. */ else if (CLASSTYPE_TEMPLATE_INFO (arg) && !CLASSTYPE_USE_TEMPLATE (arg)
is_tmpl_type && PRIMARY_TEMPLATE_P (CLASSTYPE_TI_TEMPLATE (arg)))
= ((TREE_CODE (arg) == TEMPLATE_DECL {
&& TREE_CODE (DECL_TEMPLATE_RESULT (arg)) == TYPE_DECL) if (is_base_of_enclosing_class (arg, current_class_type))
|| TREE_CODE (arg) == TEMPLATE_TEMPLATE_PARM /* This is a template name used within the scope of the
|| TREE_CODE (arg) == UNBOUND_CLASS_TEMPLATE template. It could be the template, or it could be the
|| (TREE_CODE (arg) == RECORD_TYPE instantiation. Choose whichever makes sense. */
&& CLASSTYPE_TEMPLATE_INFO (arg) is_tmpl_type = requires_tmpl_type;
&& TREE_CODE (TYPE_NAME (arg)) == TYPE_DECL else
&& DECL_ARTIFICIAL (TYPE_NAME (arg)) is_tmpl_type = 1;
&& requires_tmpl_type }
&& is_base_of_enclosing_class (arg, current_class_type))); 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 if (is_tmpl_type
&& (TREE_CODE (arg) == TEMPLATE_TEMPLATE_PARM && (TREE_CODE (arg) == TEMPLATE_TEMPLATE_PARM
|| TREE_CODE (arg) == UNBOUND_CLASS_TEMPLATE)) || TREE_CODE (arg) == UNBOUND_CLASS_TEMPLATE))
......
2002-01-02 Nathan Sidwell <nathan@codesourcery.com> 2002-01-02 Nathan Sidwell <nathan@codesourcery.com>
* g++.dg/template/ttp3.C: New test.
* g++.dg/template/friend2.C: New test. * g++.dg/template/friend2.C: New test.
* g++.old-deja/g++/brendan/crash8.C: Adjust location of error. * g++.old-deja/g++/brendan/crash8.C: Adjust location of error.
......
// { dg-do compile }
// Copyright (C) 2001 Free Software Foundation, Inc.
// Contributed by Nathan Sidwell 29 Dec 2001 <nathan@codesourcery.com>
// PR 5213. We failed to spot that class List was a template, rather
// than a non-template or specialization
template <class T> class vector { };
class OUTER {
public:
template <class T>
class List { };
vector<class List> data; // { dg-error "type/value mismatch|expected a type|ISO C" "" }
};
template <class T>
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<class List > data; // { dg-bogus "`struct List' redeclared|type/value mismatch" "" { xfail *-*-* } }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment