From patchwork Thu Jan 19 15:01:17 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 136852 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id CA08DB6EF1 for ; Fri, 20 Jan 2012 02:01:47 +1100 (EST) Comment: DKIM? See http://www.dkim.org DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=gcc.gnu.org; s=default; x=1327590109; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: Received:Message-ID:Date:From:User-Agent:MIME-Version:To:CC: Subject:Content-Type:Mailing-List:Precedence:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:Sender: Delivered-To; bh=WKfoMKH0BDSNWz5+hVfaKKP0Fbs=; b=Pg3Wte+aWl60xq9 7EsMQBSI3WWHkaE4jzgXfUePgxwc0nhT4eubw1esk6/xsGL7hCact/QwS0L9w2EK ulMzScDrV31/sRCFRPIUl1gAdtKnagi1BpwfiQmD8sh6wDePYeQMeUSU5VHUwtZY NoTS0OfAgNu+wFi0iwq3NYyLIpns= Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=gcc.gnu.org; h=Received:Received:X-SWARE-Spam-Status:X-Spam-Check-By:Received:Received:Received:Received:Message-ID:Date:From:User-Agent:MIME-Version:To:CC:Subject:Content-Type:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=Qtd93cMrhrdgbKgjGCb5RQTV/tWqtsQoqgG6aEOzM+IIwbbofg9n1wvClIiuGR v3kK/cMuuxpY+mgnOfx3prhWjA25Ylh4z3h2foolQnFIV7RCB9bv/fldY/RR51B8 /7hpmKZhEpQxcSoC/iTg3iNtoCdwZlSCbbofNQJF9MJcA=; Received: (qmail 9137 invoked by alias); 19 Jan 2012 15:01:44 -0000 Received: (qmail 9123 invoked by uid 22791); 19 Jan 2012 15:01:42 -0000 X-SWARE-Spam-Status: No, hits=-6.6 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_HI, SPF_HELO_PASS, TW_FN, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 19 Jan 2012 15:01:26 +0000 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q0JF1P9t012189 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Thu, 19 Jan 2012 10:01:25 -0500 Received: from ns3.rdu.redhat.com (ns3.rdu.redhat.com [10.11.255.199]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id q0JF1PL5005075; Thu, 19 Jan 2012 10:01:25 -0500 Received: from [0.0.0.0] (ovpn-113-118.phx2.redhat.com [10.3.113.118]) by ns3.rdu.redhat.com (8.13.8/8.13.8) with ESMTP id q0JF1Mdf012699; Thu, 19 Jan 2012 10:01:23 -0500 Message-ID: <4F18303D.80701@redhat.com> Date: Thu, 19 Jan 2012 10:01:17 -0500 From: Jason Merrill User-Agent: Mozilla/5.0 (X11; Linux i686; rv:9.0) Gecko/20111222 Thunderbird/9.0 MIME-Version: 1.0 To: gcc-patches List CC: Jakub Jelinek , =?ISO-8859-1?Q?Fabien_Ch=EAne?= , Than Ngo Subject: C++ PATCH for c++/51889 (problem overloading function using in template) Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org 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. commit 542a826b421991226a5083f769fd1054339b4ff6 Author: Jason Merrill 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 +struct B: A +{ + using A::f; + void f(); +};