aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorKriang Lerdsuwanakij <lerdsuwa@users.sourceforge.net>2002-07-17 14:17:21 +0000
committerKriang Lerdsuwanakij <lerdsuwa@gcc.gnu.org>2002-07-17 14:17:21 +0000
commitd955f6ea6f555019be4227cb1f48b691483cf275 (patch)
tree7233f26cf7a716b8c04adeaf35c062057062b6a1 /gcc
parentd03d18e8deab04e1b9c79d84fe91432abdf7ddf3 (diff)
downloadgcc-d955f6ea6f555019be4227cb1f48b691483cf275.zip
gcc-d955f6ea6f555019be4227cb1f48b691483cf275.tar.gz
gcc-d955f6ea6f555019be4227cb1f48b691483cf275.tar.bz2
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
Diffstat (limited to 'gcc')
-rw-r--r--gcc/cp/ChangeLog6
-rw-r--r--gcc/cp/pt.c60
-rw-r--r--gcc/testsuite/ChangeLog5
-rw-r--r--gcc/testsuite/g++.dg/template/instantiate2.C8
-rw-r--r--gcc/testsuite/g++.dg/template/spec4.C11
5 files changed, 68 insertions, 22 deletions
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 <lerdsuwa@users.sourceforge.net>
+ PR c++/2862, c++/2863
+ * pt.c (determine_specialization): Compare the length of
+ TYPE_ARG_TYPES. Tidy.
+
+2002-07-17 Kriang Lerdsuwanakij <lerdsuwa@users.sourceforge.net>
+
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 <class T> void f(int i = 0);
+ template <> void f<int>();
+ The specialization f<int> 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 <lerdsuwa@users.sourceforge.net>
+ * g++.dg/template/instantiate2.C: New test.
+ * g++.dg/template/spec4.C: New test.
+
+2002-07-17 Kriang Lerdsuwanakij <lerdsuwa@users.sourceforge.net>
+
* 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 <wolfgang.bangerth@iwr.uni-heidelberg.de>
+
+// PR c++/2862
+// Default function argument and template instantiation.
+
+template <int dim> 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 <wolfgang.bangerth@iwr.uni-heidelberg.de>
+
+// PR c++/2863
+// Default function argument and template specialization.
+
+struct X {
+ template <int dim> void f(int=0);
+};
+
+template <> void X::f<1> () {} // { dg-error "(not match|syntax error)" }