class.c (add_method): Compare template parms too.
authorNathan Sidwell <nathan@codesourcery.com>
Fri, 18 Oct 2002 08:09:58 +0000 (08:09 +0000)
committerNathan Sidwell <nathan@gcc.gnu.org>
Fri, 18 Oct 2002 08:09:58 +0000 (08:09 +0000)
cp:
* class.c (add_method): Compare template parms too.
testsuite:
* g++.dg/overload/member2.C: New test.

From-SVN: r58278

gcc/cp/ChangeLog
gcc/cp/class.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/overload/member2.C [new file with mode: 0644]

index b6836eef407e720b75782ed679cb86e3ad51e49f..e2a0976f7a108870219ce8067dc8617a4e1ed1f3 100644 (file)
@@ -1,3 +1,7 @@
+2002-10-17  Nathan Sidwell  <nathan@codesourcery.com>
+
+       * class.c (add_method): Compare template parms too.
+
 2002-10-17  Mark Mitchell  <mark@codesourcery.com>
 
        PR c++/7584
index 90d7ef2c92180b9e99c70c2dcdd77b8dea7e722f..7c660980c5774fbd3f1b21bed5e039093bdbdf0b 100644 (file)
@@ -950,6 +950,13 @@ add_method (type, method, error_p)
              && (TYPE_QUALS (TREE_TYPE (TREE_VALUE (parms1)))
                  != TYPE_QUALS (TREE_TYPE (TREE_VALUE (parms2)))))
            same = 0;
+         
+         /* For templates, the template parms must be identical.  */
+         if (TREE_CODE (fn) == TEMPLATE_DECL
+             && !comp_template_parms (DECL_TEMPLATE_PARMS (fn),
+                                      DECL_TEMPLATE_PARMS (method)))
+           same = 0;
+         
          if (! DECL_STATIC_FUNCTION_P (fn))
            parms1 = TREE_CHAIN (parms1);
          if (! DECL_STATIC_FUNCTION_P (method))
index f718424a935be15a7e5ec8e1f53bc7032e635c33..20fda9f5999cd014740d3dbc30dd6cb8ffe59c39 100644 (file)
@@ -1,3 +1,7 @@
+2002-10-17  Nathan Sidwell  <nathan@codesourcery.com>
+
+       * g++.dg/overload/member2.C: New test.
+
 2002-10-17  Janis Johnson  <janis187@us.ibm.com>
 
        * g++.dg/README: Describe new compat directory.
diff --git a/gcc/testsuite/g++.dg/overload/member2.C b/gcc/testsuite/g++.dg/overload/member2.C
new file mode 100644 (file)
index 0000000..b891414
--- /dev/null
@@ -0,0 +1,41 @@
+// { dg-do run }
+
+// Copyright (C) 2001 Free Software Foundation, Inc.
+// Contributed by Nathan Sidwell 17 Oct 2002 <nathan@codesourcery.com>
+
+// PR 7676. We didn't notice template members were different.
+
+struct foo
+{
+  template<class T>
+  int bar() {return 1;}
+  
+  template<int I>
+  int bar() {return 2;}
+    
+};
+
+struct baz : foo
+{
+  using foo::bar;
+  template<int I>
+  int bar () {return 3;}
+};
+
+int main ()
+{
+  baz b;
+  foo f;
+
+  if (f.bar<1> () != 2)
+    return 1;
+  if (f.bar<int> () != 1)
+    return 2;
+  
+  if (b.bar<1> () != 3)
+    return 1;
+  if (b.bar<int> () != 1)
+    return 2;
+
+  return 0;
+}