From e58d4228453c9e7036259acd104222bff680a880 Mon Sep 17 00:00:00 2001 From: Jason Merrill Date: Thu, 19 Jan 2012 09:58:28 -0500 Subject: [PATCH] re PR c++/51889 (can't override a using-declaration in a template) 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 | 6 ++++++ gcc/cp/class.c | 12 ++++++++++++ gcc/cp/semantics.c | 14 -------------- gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/g++.dg/inherit/using7.C | 12 ++++++++++++ 5 files changed, 35 insertions(+), 14 deletions(-) create mode 100644 gcc/testsuite/g++.dg/inherit/using7.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index b0660ce57af..adec9249adf 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2012-01-19 Jason Merrill + + 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 PR c++/51225 diff --git a/gcc/cp/class.c b/gcc/cp/class.c index 9b957fec36f..e6f33fe47ac 100644 --- a/gcc/cp/class.c +++ b/gcc/cp/class.c @@ -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; diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c index 40676b6b809..a5a10d02c89 100644 --- a/gcc/cp/semantics.c +++ b/gcc/cp/semantics.c @@ -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; diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 2fe1ddd13d3..ea028e13bbe 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2012-01-19 Jason Merrill + + PR c++/51889 + * g++.dg/inherit/using7.C: New. + 2012-01-19 Richard Guenther 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 index 00000000000..de177c91d21 --- /dev/null +++ b/gcc/testsuite/g++.dg/inherit/using7.C @@ -0,0 +1,12 @@ +// PR c++/51889 + +struct A { + void f(); +}; + +template +struct B: A +{ + using A::f; + void f(); +}; -- 2.30.2