]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR c++/11697 (Failure to diagnose class template redeclaration via using declaration)
authorMark Mitchell <mark@codesourcery.com>
Fri, 1 Aug 2003 18:48:50 +0000 (18:48 +0000)
committerMark Mitchell <mmitchel@gcc.gnu.org>
Fri, 1 Aug 2003 18:48:50 +0000 (18:48 +0000)
PR c++/11697
* decl.c (decls_match): Don't ignore the types of template
classes.

PR c++/11744
* pt.c (tsubst_copy_and_build): Refine Koenig lookup logic.

PR c++/11697
* g++.dg/template/using6.C: New test.

PR c++/11744
* g++.dg/template/koenig2.C: New test.

From-SVN: r70062

gcc/cp/ChangeLog
gcc/cp/decl.c
gcc/cp/pt.c
gcc/cp/semantics.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/template/koenig2.C [new file with mode: 0644]
gcc/testsuite/g++.dg/template/using6.C [new file with mode: 0644]

index c50f99f6fb3c2fceab644c7899484f2ecee0f20c..9ce5c5e3d698598ad848d61071e33b216b1eb613 100644 (file)
@@ -1,3 +1,12 @@
+2003-08-01  Mark Mitchell  <mark@codesourcery.com>
+
+       PR c++/11697
+       * decl.c (decls_match): Don't ignore the types of template
+       classes.
+
+       PR c++/11744
+       * pt.c (tsubst_copy_and_build): Refine Koenig lookup logic.
+
 2003-08-01  Kriang Lerdsuwanakij  <lerdsuwa@users.sourceforge.net>
 
        PR c++/8442, c++/8806
index 95984c9be06ea8abcbba1e2e115269dcf63708cf..593dcede6e6ba4d89cad3444dfd10844d4124bb4 100644 (file)
@@ -2758,16 +2758,17 @@ decls_match (tree newdecl, tree olddecl)
     }
   else if (TREE_CODE (newdecl) == TEMPLATE_DECL)
     {
-      if (!comp_template_parms (DECL_TEMPLATE_PARMS (newdecl),
-                               DECL_TEMPLATE_PARMS (olddecl)))
-       return 0;
-
       if (TREE_CODE (DECL_TEMPLATE_RESULT (newdecl))
          != TREE_CODE (DECL_TEMPLATE_RESULT (olddecl)))
        return 0;
 
+      if (!comp_template_parms (DECL_TEMPLATE_PARMS (newdecl),
+                               DECL_TEMPLATE_PARMS (olddecl)))
+       return 0;
+
       if (TREE_CODE (DECL_TEMPLATE_RESULT (newdecl)) == TYPE_DECL)
-       types_match = 1;
+       types_match = same_type_p (TREE_TYPE (DECL_TEMPLATE_RESULT (olddecl)),
+                                  TREE_TYPE (DECL_TEMPLATE_RESULT (newdecl)));
       else
        types_match = decls_match (DECL_TEMPLATE_RESULT (olddecl),
                                   DECL_TEMPLATE_RESULT (newdecl));
index d2e6bf33f81a0126b6cddb81f543ebc0ff4c4198..2c9668f94a8f1dc73271b86bdbb849270e90399a 100644 (file)
@@ -8116,8 +8116,21 @@ tsubst_copy_and_build (tree t,
        tree function;
        tree call_args;
        bool qualified_p;
+       bool koenig_p;
 
        function = TREE_OPERAND (t, 0);
+       /* To determine whether or not we should perform Koenig lookup
+          we must look at the form of the FUNCTION.  */
+       koenig_p = !(/* Koenig lookup does not apply to qualified
+                       names.  */
+                    TREE_CODE (function) == SCOPE_REF
+                    /* Or to references to members of classes.  */
+                    || TREE_CODE (function) == COMPONENT_REF
+                    /* If it is a FUNCTION_DECL or a baselink, then
+                       the name was already resolved when the
+                       template was parsed.  */
+                    || TREE_CODE (function) == FUNCTION_DECL
+                    || TREE_CODE (function) == BASELINK);
        if (TREE_CODE (function) == SCOPE_REF)
          {
            qualified_p = true;
@@ -8140,7 +8153,7 @@ tsubst_copy_and_build (tree t,
        if (BASELINK_P (function))
          qualified_p = 1;
 
-       if (!qualified_p
+       if (koenig_p
            && TREE_CODE (function) != TEMPLATE_ID_EXPR
            && (is_overloaded_fn (function)
                || DECL_P (function)
index 80a3d60136db4ee27780a8127ea82db70b81f0ef..a5130a5bfbeee0e1f63228dc58d29590a4b241dc 100644 (file)
@@ -2354,7 +2354,7 @@ finish_id_expression (tree id_expression,
      required.  If the template-id was for a template-class, we
      will sometimes have a TYPE_DECL at this point.  */
   else if (TREE_CODE (decl) == TEMPLATE_ID_EXPR
-      || TREE_CODE (decl) == TYPE_DECL)
+          || TREE_CODE (decl) == TYPE_DECL)
     ;
   /* Look up the name.  */
   else 
index b8e827c0f85a0713ecff2f16a69cb9bcd5d41ef1..fef0f33d22163182317580656840fe0b9a217690 100644 (file)
@@ -1,3 +1,11 @@
+2003-08-01  Mark Mitchell  <mark@codesourcery.com>
+
+       PR c++/11697
+       * g++.dg/template/using6.C: New test.
+
+       PR c++/11744
+       * g++.dg/template/koenig2.C: New test.
+
 2003-08-01  Kriang Lerdsuwanakij  <lerdsuwa@users.sourceforge.net>
 
        PR c++/7983
diff --git a/gcc/testsuite/g++.dg/template/koenig2.C b/gcc/testsuite/g++.dg/template/koenig2.C
new file mode 100644 (file)
index 0000000..be072a4
--- /dev/null
@@ -0,0 +1,25 @@
+namespace nsp_foo {
+
+  struct A {};
+
+  struct foo {};
+
+}
+
+namespace nsp_bar {
+
+  void foo(nsp_foo::A) {}
+
+  template <class T>
+  void bar(T t)
+  {
+    nsp_bar::foo(t); // line 16
+  }
+
+}
+
+int main()
+{
+  nsp_bar::bar(nsp_foo::A());
+}
+
diff --git a/gcc/testsuite/g++.dg/template/using6.C b/gcc/testsuite/g++.dg/template/using6.C
new file mode 100644 (file)
index 0000000..ee8d5be
--- /dev/null
@@ -0,0 +1,14 @@
+namespace foo {
+  template<typename T>
+  struct A {};
+}
+
+namespace bar {
+  template<typename T>
+  struct A {};
+}
+
+namespace foo {
+  using bar::A; // { dg-error "" }
+}
+