This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[patch] Fix PR c++/28860: Trouble with bound template template parameter in specialization
- From: Volker Reichelt <reichelt at igpm dot rwth-aachen dot de>
- To: gcc-patches at gcc dot gnu dot org
- Date: Sat, 26 Aug 2006 23:51:44 +0200 (CEST)
- Subject: [patch] Fix PR c++/28860: Trouble with bound template template parameter in specialization
The compiler ICEs on the following invalid code snippet since GCC 3.0:
template<template<int> class A> class A<0> {};
bug.cc:1: internal compiler error: tree check: expected record_type or union_type or qual_union_type, have bound_template_template_parm in xref_basetypes, at cp/decl.c:9788
Please submit a full bug report, [etc.]
In addition the compiler accepts the following similar invalid code snippet:
template<template<int> class A> class A<0>;
The following patch adds a check for BOUND_TEMPLATE_TEMPLATE_PARM to
maybe_process_partial_specialization to emit a proper diagnostic in
both cases.
This wouldn't prevent the ICE in the first case, though. Therefore
the patch adds a return value to maybe_process_partial_specialization.
If an error occured the return value is an error_mark_node, otherwise
the TYPE is just passed through. In cp_parser_class_head the return
value is then used.
Bootstrapped and regtested on x86_64-unknown-linux-gnu.
Ok for mainline, 4.1 branch, and 4.0 branch?
Regards,
Volker
:ADDPATCH C++:
2006-08-26 Volker Reichelt <reichelt@igpm.rwth-aachen.de>
PR c++/28860
* cp-tree.h (maybe_process_partial_specialization): Return
tree instead of void.
* parser.c (cp_parser_class_head): Use return value of
maybe_process_partial_specialization.
* pt.c (maybe_process_partial_specialization): Return error_mark_node
for broken specializations, TYPE otherwise. Check for template
template parameters.
===================================================================
--- gcc/gcc/cp/cp-tree.h 2006-07-28 03:56:58 +0200
+++ gcc/gcc/cp/cp-tree.h 2006-08-20 02:38:17 +0200
@@ -4111,7 +4111,7 @@ extern int template_class_depth (tree)
extern int is_specialization_of (tree, tree);
extern bool is_specialization_of_friend (tree, tree);
extern int comp_template_args (tree, tree);
-extern void maybe_process_partial_specialization (tree);
+extern tree maybe_process_partial_specialization (tree);
extern tree most_specialized_instantiation (tree);
extern void print_candidates (tree);
extern void instantiate_pending_templates (int);
===================================================================
--- gcc/gcc/cp/parser.c 2006-08-03 04:49:07 +0200
+++ gcc/gcc/cp/parser.c 2006-08-20 02:38:56 +0200
@@ -13329,7 +13329,7 @@ cp_parser_class_head (cp_parser* parser,
if (template_id_p)
{
type = TREE_TYPE (id);
- maybe_process_partial_specialization (type);
+ type = maybe_process_partial_specialization (type);
if (nested_name_specifier)
pushed_scope = push_scope (nested_name_specifier);
}
===================================================================
--- gcc/gcc/cp/pt.c 2006-08-09 20:43:06 +0200
+++ gcc/gcc/cp/pt.c 2006-08-20 02:37:38 +0200
@@ -674,13 +674,20 @@ check_explicit_instantiation_namespace (
/* The TYPE is being declared. If it is a template type, that means it
is a partial specialization. Do appropriate error-checking. */
-void
+tree
maybe_process_partial_specialization (tree type)
{
tree context;
if (type == error_mark_node)
- return;
+ return error_mark_node;
+
+ if (TREE_CODE (type) == BOUND_TEMPLATE_TEMPLATE_PARM)
+ {
+ error ("name of class shadows template template parameter %qD",
+ TYPE_NAME (type));
+ return error_mark_node;
+ }
context = TYPE_CONTEXT (type);
@@ -765,7 +772,12 @@ maybe_process_partial_specialization (tr
}
}
else if (processing_specialization)
- error ("explicit specialization of non-template %qT", type);
+ {
+ error ("explicit specialization of non-template %qT", type);
+ return error_mark_node;
+ }
+
+ return type;
}
/* Returns nonzero if we can optimize the retrieval of specializations
===================================================================
2006-08-26 Volker Reichelt <reichelt@igpm.rwth-aachen.de>
PR c++/28860
* g++.dg/template/ttp22.C: New test.
===================================================================
--- gcc/gcc/testsuite/g++.dg/template/ttp22.C 2003-09-23 19:59:22 +0200
+++ gcc/gcc/testsuite/g++.dg/template/ttp22.C 2006-08-20 00:52:06 +0200
@@ -0,0 +1,8 @@
+// PR c++/28860
+// { dg-do compile}
+
+template<template<int> class A>
+class A<0>; // { dg-error "shadows template template parameter" }
+
+template<template<int> class B>
+class B<0> {}; // { dg-error "shadows template template parameter" }
===================================================================