PR c++/2862, c++/2863
authorKriang Lerdsuwanakij <lerdsuwa@users.sourceforge.net>
Wed, 17 Jul 2002 14:17:21 +0000 (14:17 +0000)
committerKriang Lerdsuwanakij <lerdsuwa@gcc.gnu.org>
Wed, 17 Jul 2002 14:17:21 +0000 (14:17 +0000)
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
gcc/cp/pt.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/template/instantiate2.C [new file with mode: 0644]
gcc/testsuite/g++.dg/template/spec4.C [new file with mode: 0644]

index 6975f32923f56c44c05ecda05e228acc03da22a2..de620fe5010c2825b9d7baa056274e882f2efec4 100644 (file)
@@ -1,3 +1,9 @@
+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
index 98a9f31211c4ede4e0ca6a8a56deab0e54046a66..8caf0a04a4f861dfba222930a685a2125a4bdd90 100644 (file)
@@ -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))
index a08eab9691dfb790e6fbc4aefd11e7f5bb1fa51b..1cef63b62d79fffb313447fc5722ba153bfbf6c7 100644 (file)
@@ -1,3 +1,8 @@
+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.
diff --git a/gcc/testsuite/g++.dg/template/instantiate2.C b/gcc/testsuite/g++.dg/template/instantiate2.C
new file mode 100644 (file)
index 0000000..a76eaa4
--- /dev/null
@@ -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 (file)
index 0000000..97ee4fc
--- /dev/null
@@ -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)" }