* C++ PATCH for c++/51889 (problem overloading function using in template)
@ 2012-01-19 15:01 Jason Merrill
2012-01-24 21:26 ` Fabien Chêne
0 siblings, 1 reply; 2+ messages in thread
From: Jason Merrill @ 2012-01-19 15:01 UTC (permalink / raw)
To: gcc-patches List; +Cc: Jakub Jelinek, Fabien Chêne, Than Ngo
[-- Attachment #1: Type: text/plain, Size: 698 bytes --]
When we have a class-scope using-declaration that nominates functions,
we want to insert those functions into the derived class'
CLASSTYPE_METHOD_VEC. In non-template code we do this in
handle_using_decl, which is called from check_bases_and_members. But we
don't call that function for a class template definition. Previously,
for templates we were inserting them from finish_member_declaration, but
that leads to name collisions if a function with the same signature is
declared after the using-declaration, as in this testcase. So this
patch delays inserting the used function until finish_struct time, to
match the non-template case.
Tested x86_64-pc-linux-gnu, applied to trunk.
[-- Attachment #2: 51889.patch --]
[-- Type: text/x-patch, Size: 2406 bytes --]
commit 542a826b421991226a5083f769fd1054339b4ff6
Author: Jason Merrill <jason@redhat.com>
Date: Thu Jan 19 00:53:45 2012 -0500
PR c++/51889
* class.c (finish_struct): Call add_method here for function usings.
* semantics.c (finish_member_declaration): Not here.
diff --git a/gcc/cp/class.c b/gcc/cp/class.c
index 9b957fe..e6f33fe 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 40676b6..a5a10d0 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/g++.dg/inherit/using7.C b/gcc/testsuite/g++.dg/inherit/using7.C
new file mode 100644
index 0000000..de177c9
--- /dev/null
+++ b/gcc/testsuite/g++.dg/inherit/using7.C
@@ -0,0 +1,12 @@
+// PR c++/51889
+
+struct A {
+ void f();
+};
+
+template <class T>
+struct B: A
+{
+ using A::f;
+ void f();
+};
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: C++ PATCH for c++/51889 (problem overloading function using in template)
2012-01-19 15:01 C++ PATCH for c++/51889 (problem overloading function using in template) Jason Merrill
@ 2012-01-24 21:26 ` Fabien Chêne
0 siblings, 0 replies; 2+ messages in thread
From: Fabien Chêne @ 2012-01-24 21:26 UTC (permalink / raw)
To: Jason Merrill; +Cc: gcc-patches List
2012/1/19 Jason Merrill <jason@redhat.com>:
> When we have a class-scope using-declaration that nominates functions, we
> want to insert those functions into the derived class' CLASSTYPE_METHOD_VEC.
> In non-template code we do this in handle_using_decl, which is called from
> check_bases_and_members. But we don't call that function for a class
> template definition. Previously, for templates we were inserting them from
> finish_member_declaration, but that leads to name collisions if a function
> with the same signature is declared after the using-declaration, as in this
> testcase. So this patch delays inserting the used function until
> finish_struct time, to match the non-template case.
Thanks for fixing it !
--
Fabien
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2012-01-24 21:26 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-01-19 15:01 C++ PATCH for c++/51889 (problem overloading function using in template) Jason Merrill
2012-01-24 21:26 ` Fabien Chêne
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).