[C++ PATCH] Avoid ice-on-invalid in xref_basetypes (PR c++/34089, take 2)
Jakub Jelinek
jakub@redhat.com
Tue Nov 20 16:57:00 GMT 2007
On Mon, Nov 19, 2007 at 09:01:58PM -0800, Mark Mitchell wrote:
> Jakub Jelinek wrote:
>
> > 2007-11-19 Jakub Jelinek <jakub@redhat.com>
> >
> > PR c++/34089
> > * parser.c (cp_parser_class_specifier): Don't call xref_basetypes
> > if type is not aggregate type.
> >
> > * g++.dg/template/crash74.C: New test.
>
> This seems like it would work, but why are we event accepting this code
> in cp_parser_class_head?
>
> +template<typename F> void foo () { }
> +template<typename F> struct foo<F> { };
>
> Here, we know that foo is not a name for a class template, so we should
> be able to detect the error at that point.
Like this?
2007-11-20 Jakub Jelinek <jakub@redhat.com>
PR c++/34089
* parser.c (cp_parser_class_head): Reject function template ids.
* g++.dg/template/crash74.C: New test.
--- gcc/cp/parser.c.jj 2007-11-20 11:31:07.000000000 +0100
+++ gcc/cp/parser.c 2007-11-20 14:51:47.000000000 +0100
@@ -14536,8 +14536,18 @@ cp_parser_class_head (cp_parser* parser,
/* Look up the type. */
if (template_id_p)
{
- type = TREE_TYPE (id);
- type = maybe_process_partial_specialization (type);
+ if (TREE_CODE (id) == TEMPLATE_ID_EXPR
+ && (DECL_FUNCTION_TEMPLATE_P (TREE_OPERAND (id, 0))
+ || TREE_CODE (TREE_OPERAND (id, 0)) == OVERLOAD))
+ {
+ error ("function template %qD redeclared as a class template", id);
+ type = error_mark_node;
+ }
+ else
+ {
+ type = TREE_TYPE (id);
+ type = maybe_process_partial_specialization (type);
+ }
if (nested_name_specifier)
pushed_scope = push_scope (nested_name_specifier);
}
--- gcc/testsuite/g++.dg/template/crash74.C.jj 2007-11-20 14:08:53.000000000 +0100
+++ gcc/testsuite/g++.dg/template/crash74.C 2007-11-20 14:52:25.000000000 +0100
@@ -0,0 +1,6 @@
+// PR c++/34089
+// { dg-do compile }
+// { dg-options "" }
+
+template<typename F> void foo () { }
+template<typename F> struct foo<F> { }; // { dg-error "redeclared as" }
Jakub
More information about the Gcc-patches
mailing list