From patchwork Mon Jan 24 15:22:14 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dodji Seketeli X-Patchwork-Id: 80180 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 2A3C0B7124 for ; Tue, 25 Jan 2011 02:22:36 +1100 (EST) Received: (qmail 23457 invoked by alias); 24 Jan 2011 15:22:32 -0000 Received: (qmail 23443 invoked by uid 22791); 24 Jan 2011 15:22:29 -0000 X-SWARE-Spam-Status: No, hits=-5.6 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, 24 Jan 2011 15:22:19 +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.13.8/8.13.8) with ESMTP id p0OFMHL4021886 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Mon, 24 Jan 2011 10:22:17 -0500 Received: from adjoa.redhat.com (ovpn-113-80.phx2.redhat.com [10.3.113.80]) by int-mx12.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id p0OFMFex018666; Mon, 24 Jan 2011 10:22:16 -0500 From: Dodji Seketeli To: Jason Merrill Cc: GCC Patches Subject: PR c++/47398 X-URL: http://www.redhat.com Date: Mon, 24 Jan 2011 16:22:14 +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, lookup_template_class resolves transform in #1 to the wrong one; it picks up the one in #0 instead. This is because to compare the two A comp_template_args uses cp_tree_equal that fails to consider the number of siblings of parm 'a'. The patch makes cp_tree_equal takes the number of template parameters in account when comparing TEMPLATE_PARM_INDEXes. Tested on x86_64-unknown-linux-gnu against trunk. diff --git a/gcc/cp/tree.c b/gcc/cp/tree.c index 1a1f150..d62d242 100644 --- a/gcc/cp/tree.c +++ b/gcc/cp/tree.c @@ -2176,6 +2176,9 @@ cp_tree_equal (tree t1, tree t2) BASELINK_FUNCTIONS (t2))); case TEMPLATE_PARM_INDEX: + if (TEMPLATE_PARM_NUM_SIBLINGS (t1) + != TEMPLATE_PARM_NUM_SIBLINGS (t2)) + return false; return (TEMPLATE_PARM_IDX (t1) == TEMPLATE_PARM_IDX (t2) && TEMPLATE_PARM_LEVEL (t1) == TEMPLATE_PARM_LEVEL (t2) && (TEMPLATE_PARM_PARAMETER_PACK (t1) diff --git a/gcc/testsuite/g++.dg/template/param1.C b/gcc/testsuite/g++.dg/template/param1.C index ad7fc8c..a8c3791 100644 --- a/gcc/testsuite/g++.dg/template/param1.C +++ b/gcc/testsuite/g++.dg/template/param1.C @@ -2,11 +2,11 @@ // Origin: Volker Reichelt // { dg-do compile } -template struct A +template struct A // { dg-error "declaration" } { A(); }; -template A::A() {} // { dg-error "got 2|but 1 required" } +template A::A() {} // { dg-error "invalid use of incomplete type" } A<0> a; diff --git a/gcc/testsuite/g++.dg/template/typedef37.C b/gcc/testsuite/g++.dg/template/typedef37.C new file mode 100644 index 0000000..eefa383 --- /dev/null +++ b/gcc/testsuite/g++.dg/template/typedef37.C @@ -0,0 +1,58 @@ +// Origin: PR c++/47398 +// { dg-do compile } + +template +struct A +{ + typedef int INT; +}; + +template +struct transform +{ + static int bar(); +}; + +template +struct B +{ + typedef typename A::INT TINT; + void baz(); +}; + +template +struct B +{ + typedef typename A::INT TINT; + void foo(); +}; + +template +void +B::baz() +{ + int c = transform::bar();//#0 +} + +template +void +B::foo() +{ + int c = transform::bar();//#1 +} + +int +main() +{ + B i; + i.foo(); + // While instantiating + // + // template void B::foo() + // + // lookup_template_class resolves transform in #1 to + // the wrong one; it picks up the one in #0 instead. This is because + // to compare the two A comp_template_args uses cp_tree_equal + // that fails to consider the number of siblings of parm 'a'. +return 0; +}