From d955f6ea6f555019be4227cb1f48b691483cf275 Mon Sep 17 00:00:00 2001 From: Kriang Lerdsuwanakij Date: Wed, 17 Jul 2002 14:17:21 +0000 Subject: PR c++/2862, c++/2863 PR c++/2862, c++/2863 * pt.c (determine_specialization): Compare the length of TYPE_ARG_TYPES. Tidy. * g++.dg/template/instantiate2.C: New test. * g++.dg/template/spec4.C: New test. From-SVN: r55527 --- gcc/cp/ChangeLog | 6 +++ gcc/cp/pt.c | 60 ++++++++++++++++++---------- gcc/testsuite/ChangeLog | 5 +++ gcc/testsuite/g++.dg/template/instantiate2.C | 8 ++++ gcc/testsuite/g++.dg/template/spec4.C | 11 +++++ 5 files changed, 68 insertions(+), 22 deletions(-) create mode 100644 gcc/testsuite/g++.dg/template/instantiate2.C create mode 100644 gcc/testsuite/g++.dg/template/spec4.C (limited to 'gcc') diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 6975f32..de620fe 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,5 +1,11 @@ 2002-07-17 Kriang Lerdsuwanakij + PR c++/2862, c++/2863 + * pt.c (determine_specialization): Compare the length of + TYPE_ARG_TYPES. Tidy. + +2002-07-17 Kriang Lerdsuwanakij + PR c++/3797 * decl.c (duplicate_decls): Don't propagate inlining parameters from olddecl to newdecl when newdecl is a specialization of the diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index 98a9f31..8caf0a0 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -998,28 +998,58 @@ determine_specialization (template_id, decl, targs_out, for (; fns; fns = OVL_NEXT (fns)) { - tree tmpl; - tree fn = OVL_CURRENT (fns); if (TREE_CODE (fn) == TEMPLATE_DECL) - /* DECL might be a specialization of FN. */ - tmpl = fn; + { + tree decl_arg_types; + + /* DECL might be a specialization of FN. */ + + /* Adjust the type of DECL in case FN is a static member. */ + decl_arg_types = TYPE_ARG_TYPES (TREE_TYPE (decl)); + if (DECL_STATIC_FUNCTION_P (fn) + && DECL_NONSTATIC_MEMBER_FUNCTION_P (decl)) + decl_arg_types = TREE_CHAIN (decl_arg_types); + + /* Check that the number of function parameters matches. + For example, + template void f(int i = 0); + template <> void f(); + The specialization f is illegal but is not caught + by get_bindings below. */ + + if (list_length (TYPE_ARG_TYPES (TREE_TYPE (fn))) + != list_length (decl_arg_types)) + continue; + + /* See whether this function might be a specialization of this + template. */ + targs = get_bindings (fn, decl, explicit_targs); + + if (!targs) + /* We cannot deduce template arguments that when used to + specialize TMPL will produce DECL. */ + continue; + + /* Save this template, and the arguments deduced. */ + templates = tree_cons (targs, fn, templates); + } else if (need_member_template) /* FN is an ordinary member function, and we need a specialization of a member template. */ - continue; + ; else if (TREE_CODE (fn) != FUNCTION_DECL) /* We can get IDENTIFIER_NODEs here in certain erroneous cases. */ - continue; + ; else if (!DECL_FUNCTION_MEMBER_P (fn)) /* This is just an ordinary non-member function. Nothing can be a specialization of that. */ - continue; + ; else if (DECL_ARTIFICIAL (fn)) /* Cannot specialize functions that are created implicitly. */ - continue; + ; else { tree decl_arg_types; @@ -1055,21 +1085,7 @@ determine_specialization (template_id, decl, targs_out, decl_arg_types)) /* They match! */ candidates = tree_cons (NULL_TREE, fn, candidates); - - continue; } - - /* See whether this function might be a specialization of this - template. */ - targs = get_bindings (tmpl, decl, explicit_targs); - - if (!targs) - /* We cannot deduce template arguments that when used to - specialize TMPL will produce DECL. */ - continue; - - /* Save this template, and the arguments deduced. */ - templates = tree_cons (targs, tmpl, templates); } if (templates && TREE_CHAIN (templates)) diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index a08eab9..1cef63b 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,5 +1,10 @@ 2002-07-17 Kriang Lerdsuwanakij + * g++.dg/template/instantiate2.C: New test. + * g++.dg/template/spec4.C: New test. + +2002-07-17 Kriang Lerdsuwanakij + * g++.dg/template/access2.C: New test. * g++.dg/template/access3.C: New test. diff --git a/gcc/testsuite/g++.dg/template/instantiate2.C b/gcc/testsuite/g++.dg/template/instantiate2.C new file mode 100644 index 0000000..a76eaa4 --- /dev/null +++ b/gcc/testsuite/g++.dg/template/instantiate2.C @@ -0,0 +1,8 @@ +// { dg-do compile } +// Origin: Wolfgang Bangerth + +// PR c++/2862 +// Default function argument and template instantiation. + +template void f (int=0) {}; +template void f<1> (); // { dg-error "not match" } diff --git a/gcc/testsuite/g++.dg/template/spec4.C b/gcc/testsuite/g++.dg/template/spec4.C new file mode 100644 index 0000000..97ee4fc --- /dev/null +++ b/gcc/testsuite/g++.dg/template/spec4.C @@ -0,0 +1,11 @@ +// { dg-do compile } +// Origin: Wolfgang Bangerth + +// PR c++/2863 +// Default function argument and template specialization. + +struct X { + template void f(int=0); +}; + +template <> void X::f<1> () {} // { dg-error "(not match|syntax error)" } -- cgit v1.1