From patchwork Sat Dec 8 00:36:31 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 204639 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 583172C021D for ; Sat, 8 Dec 2012 16:38:13 +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=1355549894; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: Message-ID:Date:From:User-Agent:MIME-Version:To:Subject: Content-Type:Mailing-List:Precedence:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:Sender:Delivered-To; bh=RrlSWSA cRApvC/ewAu2ipJB1lkw=; b=rTRhyTLiJUG30BKHuCDUIf4dn868G2GgkDu9MI/ ovtSo/MpKT8bpSZfYiajPOKJc92JevcjzQjoM7r5Yzeta2URb/t2DwJuFTrQ+4M+ yqd1JUeIo2GBil8z4xfZIliIMuFWctZQ42jqGgp2qazYrVJRfh1o+IC8KvUTmjku sCcg= 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:Message-ID:Date:From:User-Agent:MIME-Version:To:Subject:Content-Type:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=F7b9xuO+pzVFRW1BtJPalhDaSw3mS2R+3v09WdM2QlhX6BlAiZFCaQvmx2Zpo0 vDVyYyxsDSEsZPzwYmHICWHlkFDsxfDAmENja1JGFIfsWivtuRejuElMpWsgPOh3 o9HfjnpGvP2+e7OrhT2xbYHuMDySO6oSRF03HH9hQxNvU=; Received: (qmail 5222 invoked by alias); 8 Dec 2012 05:38:07 -0000 Received: (qmail 5058 invoked by uid 22791); 8 Dec 2012 05:38:05 -0000 X-SWARE-Spam-Status: No, hits=-6.3 required=5.0 tests=AWL, BAYES_00, KHOP_RCVD_UNTRUST, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, SPF_HELO_PASS, TW_FN 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; Sat, 08 Dec 2012 05:37:59 +0000 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id qB80aXvS005555 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Fri, 7 Dec 2012 19:36:33 -0500 Received: from [10.3.113.19] ([10.3.113.19]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id qB80aW8h015218 for ; Fri, 7 Dec 2012 19:36:32 -0500 Message-ID: <50C28B8F.7060001@redhat.com> Date: Fri, 07 Dec 2012 19:36:31 -0500 From: Jason Merrill User-Agent: Mozilla/5.0 (X11; Linux i686; rv:17.0) Gecko/17.0 Thunderbird/17.0 MIME-Version: 1.0 To: gcc-patches List Subject: C++ PATCH for c++/55127 (bogus required typename) 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 My patch that introduced "instantiation-dependent" to the compiler treated all SCOPE_REFs as instantiation-dependent, on the principle that we might need to check accessibility at instantiation time. But if the member reference is public, it will always be accessible, so we don't need to worry. Tested x86_64-pc-linux-gnu, applying to trunk. commit d891f539e75bd20fd6fb303aff4a06a053f10ae6 Author: Jason Merrill Date: Fri Dec 7 14:33:08 2012 -0500 PR c++/55127 * search.c (accessible_in_template_p): New. * cp-tree.h: Declare it. * pt.c (instantiation_dependent_scope_ref_p): New. (value_dependent_expression_p): Use it. (instantiation_dependent_r): Likewise. * semantics.c (finish_decltype_type): Handle SCOPE_REF. diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h index ceac093..1733250 100644 --- a/gcc/cp/cp-tree.h +++ b/gcc/cp/cp-tree.h @@ -5489,6 +5489,7 @@ extern tree lookup_base (tree, tree, base_access, base_kind *, tsubst_flags_t); extern tree dcast_base_hint (tree, tree); extern int accessible_p (tree, tree, bool); +extern int accessible_in_template_p (tree, tree); extern tree lookup_field_1 (tree, tree, bool); extern tree lookup_field (tree, tree, int, bool); extern int lookup_fnfields_1 (tree, tree); diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index 33044e0..1bc9e1b 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -19293,6 +19293,22 @@ dependent_scope_p (tree scope) && !currently_open_class (scope)); } +/* T is a SCOPE_REF; return whether we need to consider it + instantiation-dependent so that we can check access at instantiation + time even though we know which member it resolves to. */ + +static bool +instantiation_dependent_scope_ref_p (tree t) +{ + if (DECL_P (TREE_OPERAND (t, 1)) + && CLASS_TYPE_P (TREE_OPERAND (t, 0)) + && accessible_in_template_p (TREE_OPERAND (t, 0), + TREE_OPERAND (t, 1))) + return false; + else + return true; +} + /* Returns TRUE if the EXPRESSION is value-dependent, in the sense of [temp.dep.constexpr]. EXPRESSION is already known to be a constant expression. */ @@ -19400,10 +19416,9 @@ value_dependent_expression_p (tree expression) return instantiation_dependent_expression_p (expression); case SCOPE_REF: - /* instantiation_dependent_r treats this as dependent so that we - check access at instantiation time, and all instantiation-dependent - expressions should also be considered value-dependent. */ - return true; + /* All instantiation-dependent expressions should also be considered + value-dependent. */ + return instantiation_dependent_scope_ref_p (expression); case COMPONENT_REF: return (value_dependent_expression_p (TREE_OPERAND (expression, 0)) @@ -19744,10 +19759,10 @@ instantiation_dependent_r (tree *tp, int *walk_subtrees, break; case SCOPE_REF: - /* Similarly, finish_qualified_id_expr builds up a SCOPE_REF in a - template so that we can check access at instantiation time even - though we know which member it resolves to. */ - return *tp; + if (instantiation_dependent_scope_ref_p (*tp)) + return *tp; + else + break; default: break; diff --git a/gcc/cp/search.c b/gcc/cp/search.c index 92234a5..1cd4fc5 100644 --- a/gcc/cp/search.c +++ b/gcc/cp/search.c @@ -832,6 +832,19 @@ dfs_accessible_post (tree binfo, void * /*data*/) return NULL_TREE; } +/* Like accessible_p below, but within a template returns true iff DECL is + accessible in TYPE to all possible instantiations of the template. */ + +int +accessible_in_template_p (tree type, tree decl) +{ + int save_ptd = processing_template_decl; + processing_template_decl = 0; + int val = accessible_p (type, decl, false); + processing_template_decl = save_ptd; + return val; +} + /* DECL is a declaration from a base class of TYPE, which was the class used to name DECL. Return nonzero if, in the current context, DECL is accessible. If TYPE is actually a BINFO node, diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c index 491d97c..0fa251b 100644 --- a/gcc/cp/semantics.c +++ b/gcc/cp/semantics.c @@ -5261,7 +5261,8 @@ finish_decltype_type (tree expr, bool id_expression_or_member_access_p, expr = TREE_OPERAND (expr, 0); if (TREE_CODE (expr) == OFFSET_REF - || TREE_CODE (expr) == MEMBER_REF) + || TREE_CODE (expr) == MEMBER_REF + || TREE_CODE (expr) == SCOPE_REF) /* We're only interested in the field itself. If it is a BASELINK, we will need to see through it in the next step. */ diff --git a/gcc/testsuite/g++.dg/template/defarg16.C b/gcc/testsuite/g++.dg/template/defarg16.C new file mode 100644 index 0000000..ba78bfb --- /dev/null +++ b/gcc/testsuite/g++.dg/template/defarg16.C @@ -0,0 +1,28 @@ +// PR c++/55127 + +struct some_class +{ + static const bool is_valid_type = true; +}; + +template< typename Type + , bool Valid = Type::is_valid_type +> +struct wrapper; + +template< typename Type > +struct wrapper< Type, true > +{ + typedef Type type; +}; + +template< typename T > +void fun() +{ + wrapper::type x; +} + +int main() +{ + fun(); +}