From 98f99d7f7cb37cfb836264d06b571d7c7f82f6a5 Mon Sep 17 00:00:00 2001 From: Mark Mitchell Date: Mon, 14 Mar 2005 03:54:21 +0000 Subject: [PATCH] re PR c++/20157 (Internal compiler error on invalid code) PR c++/20157 * pt.c (determine_specialization): Reject non-specializations. PR c++/20157 * g++.dg/template/error18.C: New test. From-SVN: r96414 --- gcc/cp/ChangeLog | 5 +++++ gcc/cp/pt.c | 12 ++++++++++-- gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/g++.dg/template/error18.C | 11 +++++++++++ 4 files changed, 31 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/g++.dg/template/error18.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 2d9999287c71..fefffd8056ed 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,8 @@ +2005-03-13 Mark Mitchell + + PR c++/20157 + * pt.c (determine_specialization): Reject non-specializations. + 2005-03-11 Per Bothner * cp-tree.h (struct cp_declarator): New id_loc field. diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index 2ad20b34aced..c9d2f96e3837 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -1353,8 +1353,8 @@ determine_specialization (tree template_id, /* Count the number of template headers specified for this specialization. */ header_count = 0; - for (b = current_binding_level; - b->kind == sk_template_parms || b->kind == sk_template_spec; + for (b = current_binding_level; + b->kind == sk_template_parms; b = b->level_chain) ++header_count; @@ -1423,6 +1423,14 @@ determine_specialization (tree template_id, if (header_count && header_count != template_count + 1) continue; + /* Check that the number of template arguments at the + innermost level for DECL is the same as for FN. */ + if (current_binding_level->kind == sk_template_parms + && !current_binding_level->explicit_spec_p + && (TREE_VEC_LENGTH (DECL_INNERMOST_TEMPLATE_PARMS (fn)) + != TREE_VEC_LENGTH (TREE_VALUE (current_template_parms)))) + continue; + /* See whether this function might be a specialization of this template. */ targs = get_bindings (fn, decl, explicit_targs); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 111020facd77..1b6603f1c950 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2005-03-13 Mark Mitchell + + PR c++/20157 + * g++.dg/template/error18.C: New test. + 2005-03-09 Ben Elliston PR debug/16792 diff --git a/gcc/testsuite/g++.dg/template/error18.C b/gcc/testsuite/g++.dg/template/error18.C new file mode 100644 index 000000000000..ca0762ee03df --- /dev/null +++ b/gcc/testsuite/g++.dg/template/error18.C @@ -0,0 +1,11 @@ +// PR c++/20157 + +template +struct A{ + template + void function(T); +}; + +template<> +template +void A::function(ABC); // { dg-error "" }