From patchwork Thu Jul 12 23:06:36 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 170758 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 3D9772C01F1 for ; Fri, 13 Jul 2012 09:06:59 +1000 (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=1342739220; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: Message-ID:Date:From:User-Agent:MIME-Version:To:CC:Subject: References:In-Reply-To:Content-Type:Mailing-List:Precedence: List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender: Delivered-To; bh=dMvuHChHiBGPMpqfffQZOtvBFDQ=; b=rOlCZONVM/UgACS izyCc9rtpT59lLoOkljtkCNjwAPio1Yhpz3w7r6+9lyIGV2dhbwbbvSseUCOq7SS +aPE/pFy+YDPuF4k2r+2n8OmWptV0pVuFHXgMhzHn25JhqeSmNC2e5uPuhfwyDAJ URjuvSWv9IK3rdA4XcxcFCPfGCmM= 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:CC:Subject:References:In-Reply-To:Content-Type:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=fMd7TXaO4zm7e+Ktz/RhRqjUumcQSGUh/ui5efXSyDSMDoB6X8BcnIKMFqjr0p NhXZ1jC5HpCc7lX8rXDCQGKIdaz9GJs7i+nJkk7705q8r023fEX4FGKb13Qv9ZEP G0FznLcMmDsQI87YMu1oeuk6UOoMvYZhJdmW4HKcvq6wA=; Received: (qmail 14278 invoked by alias); 12 Jul 2012 23:06:56 -0000 Received: (qmail 14266 invoked by uid 22791); 12 Jul 2012 23:06:55 -0000 X-SWARE-Spam-Status: No, hits=-7.0 required=5.0 tests=AWL, BAYES_00, KHOP_RCVD_UNTRUST, KHOP_THREADED, RCVD_IN_DNSWL_HI, RCVD_IN_HOSTKARMA_W, 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, 12 Jul 2012 23:06:39 +0000 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q6CN6cuv002931 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Thu, 12 Jul 2012 19:06:38 -0400 Received: from [10.36.116.40] (ovpn-116-40.ams2.redhat.com [10.36.116.40]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id q6CN6aHM023506; Thu, 12 Jul 2012 19:06:37 -0400 Message-ID: <4FFF587C.3050609@redhat.com> Date: Fri, 13 Jul 2012 01:06:36 +0200 From: Jason Merrill User-Agent: Mozilla/5.0 (X11; Linux i686; rv:13.0) Gecko/20120605 Thunderbird/13.0 MIME-Version: 1.0 To: Paolo Carlini CC: "gcc-patches@gcc.gnu.org" Subject: Re: [C++ RFC / Patch] PR 51213 ("access control under SFINAE") References: <4FDB4640.3050502@oracle.com> <4FFF55EF.3090508@redhat.com> In-Reply-To: <4FFF55EF.3090508@redhat.com> 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 And here's a fix for the access7 failure, to be applied on top of your patch. I notice that your patch changes the behavior of C++98/03 mode as well, which seems wrong to me; I think this is a big enough change that we should limit it to C++11 mode. Jason commit f60b940ab6bcbad60632ba085fa0a5cff2e963e3 Author: Jason Merrill Date: Thu Jul 12 17:16:35 2012 +0200 access7 diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h index 8ce0f2a..12c688a 100644 --- a/gcc/cp/cp-tree.h +++ b/gcc/cp/cp-tree.h @@ -78,6 +78,7 @@ c-common.h, not after. CONVERT_EXPR_VBASE_PATH (in CONVERT_EXPR) OVL_ARG_DEPENDENT (in OVERLOAD) PACK_EXPANSION_LOCAL_P (in *_PACK_EXPANSION) + TINFO_RECHECK_ACCESS_P (in TEMPLATE_INFO) 1: IDENTIFIER_VIRTUAL_P (in IDENTIFIER_NODE) TI_PENDING_TEMPLATE_FLAG. TEMPLATE_PARMS_FOR_INLINE. @@ -725,6 +726,14 @@ typedef struct qualified_typedef_usage_s qualified_typedef_usage_t; DEF_VEC_O (qualified_typedef_usage_t); DEF_VEC_ALLOC_O (qualified_typedef_usage_t,gc); +/* Non-zero if this template specialization has access violations that + should be rechecked when the function is instantiated outside argument + deduction. */ +#define TINFO_RECHECK_ACCESS_P(NODE) \ + (TREE_LANG_FLAG_0 (TEMPLATE_INFO_CHECK (NODE))) +#define FNDECL_RECHECK_ACCESS_P(NODE) \ + (TINFO_RECHECK_ACCESS_P (DECL_TEMPLATE_INFO (NODE))) + struct GTY(()) tree_template_info { struct tree_common common; VEC(qualified_typedef_usage_t,gc) *typedefs_needing_access_checking; diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index 6a1780b..7eca5c7 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -9875,10 +9875,13 @@ tsubst_decl (tree t, tree args, tsubst_flags_t complain) hash = hash_tmpl_and_args (gen_tmpl, argvec); spec = retrieve_specialization (gen_tmpl, argvec, hash); + r = spec; if (spec) { - r = spec; - break; + if (FNDECL_RECHECK_ACCESS_P (spec) && (complain & tf_error)) + /* Reinstantiate to get access errors. */; + else + break; } /* We can see more levels of arguments than parameters if @@ -9954,6 +9957,13 @@ tsubst_decl (tree t, tree args, tsubst_flags_t complain) if (type == error_mark_node) RETURN (error_mark_node); + if (r) + { + /* We're done reinstantiating for access errors. */ + gcc_assert (FNDECL_RECHECK_ACCESS_P (r)); + break; + } + /* We do NOT check for matching decls pushed separately at this point, as they may not represent instantiations of this template, and in any case are considered separate under the @@ -14347,7 +14357,13 @@ instantiate_template_1 (tree tmpl, tree orig_args, tsubst_flags_t complain) || fndecl == NULL_TREE); if (spec != NULL_TREE) - return spec; + { + if (FNDECL_RECHECK_ACCESS_P (spec) + && (complain & tf_error)) + /* Do the instantiation again, we're out of SFINAE context. */; + else + return spec; + } if (check_instantiated_args (gen_tmpl, INNERMOST_TEMPLATE_ARGS (targ_ptr), complain)) @@ -14398,7 +14414,17 @@ instantiate_template_1 (tree tmpl, tree orig_args, tsubst_flags_t complain) if (DECL_CHAIN (gen_tmpl) && DECL_CLONED_FUNCTION_P (DECL_CHAIN (gen_tmpl))) clone_function_decl (fndecl, /*update_method_vec_p=*/0); - return tmp ? error_mark_node : fndecl; + if (tmp) + { + if (!(complain & tf_error)) + { + /* Remember to reinstantiate when we're out of SFINAE so the user + can see the errors. */ + FNDECL_RECHECK_ACCESS_P (fndecl) = true; + } + return error_mark_node; + } + return fndecl; } /* Wrapper for instantiate_template_1. */ diff --git a/gcc/testsuite/g++.dg/template/access7.C b/gcc/testsuite/g++.dg/template/access7.C index bd38e4e..7d18127 100644 --- a/gcc/testsuite/g++.dg/template/access7.C +++ b/gcc/testsuite/g++.dg/template/access7.C @@ -14,5 +14,5 @@ typename A::T* f (A) { // { dg-error "this context" } } void g () { - f (S ()); // { dg-message "required" } + f (S ()); // { dg-message "required|no match" } }