From patchwork Wed Aug 17 18:51:07 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dodji Seketeli X-Patchwork-Id: 110343 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 3E766B6F8C for ; Thu, 18 Aug 2011 04:51:35 +1000 (EST) Received: (qmail 16275 invoked by alias); 17 Aug 2011 18:51:33 -0000 Received: (qmail 16264 invoked by uid 22791); 17 Aug 2011 18:51:32 -0000 X-SWARE-Spam-Status: No, hits=-6.5 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, SPF_HELO_PASS 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; Wed, 17 Aug 2011 18:51:10 +0000 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p7HIp93J021398 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Wed, 17 Aug 2011 14:51:09 -0400 Received: from localhost (ovpn-113-111.phx2.redhat.com [10.3.113.111]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id p7HIp81a018933 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Wed, 17 Aug 2011 14:51:09 -0400 Received: by localhost (Postfix, from userid 500) id 780E629C094; Wed, 17 Aug 2011 20:51:07 +0200 (CEST) From: Dodji Seketeli To: GCC Patches Cc: Jason Merrill Subject: [PATCH] PR c++/45625 - Template parm name doesn't hide outer class scope's member name X-URL: http://www.redhat.com Date: Wed, 17 Aug 2011 20:51:07 +0200 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.2 (gnu/linux) MIME-Version: 1.0 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, Consider this code snippet: struct Outer { static const int value = 1 ; template< int value > struct Inner { static const int* get_value() { return &value ; } // #1 -> Error! } ; }; template class Outer::Inner<2>; The line #1 should yield an error because the name "value" should resolve to the template parameter, not the static member of the outer class. The problem seems to be that parameter_of_template_p (notably used by binding_to_template_parms_of_scope_p) fails to detect that the template parm it gets in argument is a member of the template. For each PARM_DECL representing a non-type template parameter, process_template_parm and push_inline_template_parms_recursive actually create a CONST_DECL that is added to the symbol table for that PARM_DECL. The patch below updates parameter_of_template_p to handle non-type template parameters. Tested on x86_64-unknown-linux-gnu against trunk. gcc/cp/ * pt.c (parameter_of_template_p): Handle comparison with DECLs of template parameters as created by process_template_parm. gcc/testsuite/ * g++.dg/lookup/hidden-var1.C: New test case. --- gcc/cp/pt.c | 9 +++++++-- gcc/testsuite/g++.dg/lookup/hidden-var1.C | 19 +++++++++++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/g++.dg/lookup/hidden-var1.C diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index 9ab110a..ed4fe72 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -7890,8 +7890,13 @@ parameter_of_template_p (tree parm, tree templ) parms = INNERMOST_TEMPLATE_PARMS (parms); for (i = 0; i < TREE_VEC_LENGTH (parms); ++i) - if (parm == TREE_VALUE (TREE_VEC_ELT (parms, i))) - return true; + { + tree p = TREE_VALUE (TREE_VEC_ELT (parms, i)); + if (parm == p + || (DECL_INITIAL (parm) + && DECL_INITIAL (parm) == DECL_INITIAL (p))) + return true; + } return false; } diff --git a/gcc/testsuite/g++.dg/lookup/hidden-var1.C b/gcc/testsuite/g++.dg/lookup/hidden-var1.C new file mode 100644 index 0000000..6be32b5 --- /dev/null +++ b/gcc/testsuite/g++.dg/lookup/hidden-var1.C @@ -0,0 +1,19 @@ +// Origin PR c++/45625 +// { dg-do compile } + +struct Outer +{ + static const int value = 1 ; + + template< int value > + struct Inner + { + static const int* + get_value() + { + return &value ;// { dg-error "lvalue required" } + } + }; +}; + +template class Outer::Inner<2>;