re PR c++/51889 (can't override a using-declaration in a template)
authorJason Merrill <jason@redhat.com>
Thu, 19 Jan 2012 14:58:28 +0000 (09:58 -0500)
committerJason Merrill <jason@gcc.gnu.org>
Thu, 19 Jan 2012 14:58:28 +0000 (09:58 -0500)
PR c++/51889
* class.c (finish_struct): Call add_method here for function usings.
* semantics.c (finish_member_declaration): Not here.

From-SVN: r183304

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

index b0660ce57af3287eadeb9eb8f7f46632f52b5545..adec9249adfe79437b3ca943139bcdac51dc31fb 100644 (file)
@@ -1,3 +1,9 @@
+2012-01-19  Jason Merrill  <jason@redhat.com>
+
+       PR c++/51889
+       * class.c (finish_struct): Call add_method here for function usings.
+       * semantics.c (finish_member_declaration): Not here.
+
 2012-01-18  Paolo Carlini  <paolo.carlini@oracle.com>
 
        PR c++/51225
index 9b957fec36feea21327772fbdc05e20b1d83855e..e6f33fe47ac8e98f23ad67414e2094dd2fbebc46 100644 (file)
@@ -6195,6 +6195,18 @@ finish_struct (tree t, tree attributes)
        if (DECL_PURE_VIRTUAL_P (x))
          VEC_safe_push (tree, gc, CLASSTYPE_PURE_VIRTUALS (t), x);
       complete_vars (t);
+      /* We need to add the target functions to the CLASSTYPE_METHOD_VEC if
+        an enclosing scope is a template class, so that this function be
+        found by lookup_fnfields_1 when the using declaration is not
+        instantiated yet.  */
+      for (x = TYPE_FIELDS (t); x; x = DECL_CHAIN (x))
+       if (TREE_CODE (x) == USING_DECL)
+         {
+           tree fn = strip_using_decl (x);
+           if (is_overloaded_fn (fn))
+             for (; fn; fn = OVL_NEXT (fn))
+               add_method (t, OVL_CURRENT (fn), x);
+         }
 
       /* Remember current #pragma pack value.  */
       TYPE_PRECISION (t) = maximum_field_alignment;
index 40676b6b8092f2830524835b35acfd2e7fb2d026..a5a10d02c89f6d71ffd6b7f2a58eaea6b0229548 100644 (file)
@@ -2671,20 +2671,6 @@ finish_member_declaration (tree decl)
     {
       if (TREE_CODE (decl) == USING_DECL)
        {
-         /* We need to add the target functions to the
-            CLASSTYPE_METHOD_VEC if an enclosing scope is a template
-            class, so that this function be found by lookup_fnfields_1
-            when the using declaration is not instantiated yet.  */
-
-         tree target_decl = strip_using_decl (decl);
-         if (dependent_type_p (current_class_type)
-             && is_overloaded_fn (target_decl))
-           {
-             tree t = target_decl;
-             for (; t; t = OVL_NEXT (t))
-               add_method (current_class_type, OVL_CURRENT (t), decl);
-           }
-
          /* For now, ignore class-scope USING_DECLS, so that
             debugging backends do not see them. */
          DECL_IGNORED_P (decl) = 1;
index 2fe1ddd13d33d35afd178e896c498717946e80b4..ea028e13bbe28f3b66c786c03ad225969198026a 100644 (file)
@@ -1,3 +1,8 @@
+2012-01-19  Jason Merrill  <jason@redhat.com>
+
+       PR c++/51889
+       * g++.dg/inherit/using7.C: New.
+
 2012-01-19  Richard Guenther  <rguenther@suse.de>
 
        PR tree-optimization/37997
diff --git a/gcc/testsuite/g++.dg/inherit/using7.C b/gcc/testsuite/g++.dg/inherit/using7.C
new file mode 100644 (file)
index 0000000..de177c9
--- /dev/null
@@ -0,0 +1,12 @@
+// PR c++/51889
+
+struct A {
+  void f();
+};
+
+template <class T>
+struct B: A
+{
+  using A::f;
+  void f();
+};