From patchwork Mon Mar 7 21:12:13 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dodji Seketeli X-Patchwork-Id: 85815 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 B661BB7082 for ; Tue, 8 Mar 2011 08:12:28 +1100 (EST) Received: (qmail 15663 invoked by alias); 7 Mar 2011 21:12:25 -0000 Received: (qmail 15655 invoked by uid 22791); 7 Mar 2011 21:12:24 -0000 X-SWARE-Spam-Status: No, hits=-5.7 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_HI, SPF_HELO_PASS, 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; Mon, 07 Mar 2011 21:12:18 +0000 Received: from int-mx12.intmail.prod.int.phx2.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p27LCG4E032522 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Mon, 7 Mar 2011 16:12:16 -0500 Received: from localhost.localdomain (ovpn-113-84.phx2.redhat.com [10.3.113.84]) by int-mx12.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id p27LCFDD011900 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Mon, 7 Mar 2011 16:12:16 -0500 Received: by localhost.localdomain (Postfix, from userid 500) id 4FB0F8E606F; Mon, 7 Mar 2011 22:12:13 +0100 (CET) From: Dodji Seketeli To: Jason Merrill Cc: GCC Patches Subject: [PATCH] PR c++/47957 X-URL: http://www.redhat.com Mail-Followup-To: Jason Merrill , GCC Patches Date: Mon, 07 Mar 2011 22:12:13 +0100 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.2 (gnu/linux) MIME-Version: 1.0 X-IsSubscribed: yes 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 Hello, In the example of the patch below, the lookup of symbol 'T' yields the template parameter instead of the typedef Base::T. That's because outer_binding considers the template-parameters-scope bindings from Derived::foo even though that template doesn't have it's own template header. outer_binding should first consider the class-scope bindings from Derived::foo. The patch tightens binding_to_template_parms_of_scope_p to make it only consider template parameters of the scope of a template which has its own template header. Tested on x86_64-unknown-linux-gnu against trunk. diff --git a/gcc/cp/name-lookup.c b/gcc/cp/name-lookup.c index 4117202..18e3441 100644 --- a/gcc/cp/name-lookup.c +++ b/gcc/cp/name-lookup.c @@ -4205,8 +4205,13 @@ qualified_lookup_using_namespace (tree name, tree scope, } /* Subroutine of outer_binding. - Returns TRUE if BINDING is a binding to a template parameter of SCOPE, - FALSE otherwise. */ + + Returns TRUE if BINDING is a binding to a template parameter of + SCOPE. In that case SCOPE is the scope of a primary template + parameter -- in the sense of G++, i.e, a template that has its own + template header. + + Returns FALSE otherwise. */ static bool binding_to_template_parms_of_scope_p (cxx_binding *binding, @@ -4222,6 +4227,8 @@ binding_to_template_parms_of_scope_p (cxx_binding *binding, return (scope && scope->this_entity && get_template_info (scope->this_entity) + && PRIMARY_TEMPLATE_P (TI_TEMPLATE + (get_template_info (scope->this_entity))) && parameter_of_template_p (binding_value, TI_TEMPLATE (get_template_info \ (scope->this_entity)))); diff --git a/gcc/testsuite/g++.dg/lookup/template3.C b/gcc/testsuite/g++.dg/lookup/template3.C new file mode 100644 index 0000000..e5f6f18 --- /dev/null +++ b/gcc/testsuite/g++.dg/lookup/template3.C @@ -0,0 +1,35 @@ +// Origin PR c++/47957 +// { dg-do compile } + +struct S +{ + int m; + + S() + : m(0) + { + } +}; + +struct Base +{ + typedef S T; +}; + +template +struct Derived : public Base +{ + int + foo() + { + T a; // This is Base::T, not the template parameter. + return a.m; + } +}; + +int +main() +{ + Derived d; + return d.foo(); +}