From patchwork Thu Aug 2 16:21:58 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Carlini X-Patchwork-Id: 174782 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 8D5842C0079 for ; Fri, 3 Aug 2012 02:22:29 +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=1344529349; h=Comment: DomainKey-Signature:Received:Received: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=jm8a3dQm5GiANLjH5QdEhAW8STs=; b=PKBe7LmoH43h/9Bb2TEavZMqTp1RgkeQaJCSqclxvRE4QrdH1B22ZtRzLuss2l 4YiDRJjcgXQXSsSTC+BJwUL5NvAUQFYQ2u0KdtkbP0214fBAbVJ4jJgMsjrqVV0Q QnB2YTG/nXJnwHVKZ5H9ZHf0fDiETxlakVB5WHo476SKY= 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:Received:Received:Message-ID:Date:From:User-Agent:MIME-Version:To:CC:Subject:References:In-Reply-To:Content-Type:X-IsSubscribed:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=Q+1keXF5bB+lL2hLiZ1DCU148aBTZ08yKHtNoHWIWHQhrTmONY2ap+n07+9Wgm DLZl/E4FplyCH/erpP58eGlOYPrMCeZ3hdpvZ6fUWRQ3xR4zLSMlYwypiLl8Z9LR 9QvLpXxGFzUEBEjarGej3ccuJAPo3a0GaK4QBhttfv2zA=; Received: (qmail 25899 invoked by alias); 2 Aug 2012 16:22:22 -0000 Received: (qmail 25880 invoked by uid 22791); 2 Aug 2012 16:22:18 -0000 X-SWARE-Spam-Status: No, hits=-7.4 required=5.0 tests=AWL, BAYES_00, KHOP_RCVD_UNTRUST, KHOP_THREADED, RCVD_IN_DNSWL_HI, RCVD_IN_HOSTKARMA_NO, RCVD_IN_HOSTKARMA_YE, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from acsinet15.oracle.com (HELO acsinet15.oracle.com) (141.146.126.227) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 02 Aug 2012 16:22:04 +0000 Received: from acsinet21.oracle.com (acsinet21.oracle.com [141.146.126.237]) by acsinet15.oracle.com (Sentrion-MTA-4.2.2/Sentrion-MTA-4.2.2) with ESMTP id q72GM1oR029166 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Thu, 2 Aug 2012 16:22:02 GMT Received: from acsmt357.oracle.com (acsmt357.oracle.com [141.146.40.157]) by acsinet21.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id q72GM1pK025981 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Thu, 2 Aug 2012 16:22:01 GMT Received: from abhmt105.oracle.com (abhmt105.oracle.com [141.146.116.57]) by acsmt357.oracle.com (8.12.11.20060308/8.12.11) with ESMTP id q72GM1dS016966; Thu, 2 Aug 2012 11:22:01 -0500 Received: from [192.168.1.4] (/79.43.235.191) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 02 Aug 2012 09:22:00 -0700 Message-ID: <501AA926.60607@oracle.com> Date: Thu, 02 Aug 2012 18:21:58 +0200 From: Paolo Carlini User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:14.0) Gecko/20120713 Thunderbird/14.0 MIME-Version: 1.0 To: Jason Merrill CC: "gcc-patches@gcc.gnu.org" Subject: Re: [RFC / RFH] Re-opened C++/51213 (access control under SFINAE) References: <50190E4D.4070109@oracle.com> <50193DF6.1030502@redhat.com> <50194FEF.1000201@oracle.com> <501968E2.3010803@redhat.com> <50197834.8090201@oracle.com> <50197C1E.9090707@oracle.com> <501A9DD0.5060906@redhat.com> In-Reply-To: <501A9DD0.5060906@redhat.com> 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 Hi, On 08/02/2012 05:33 PM, Jason Merrill wrote: > On 08/01/2012 02:57 PM, Paolo Carlini wrote: >> So, it is possible that when spec != NULL_TREE and we are once more in a >> SFINAE context, we have to actually call perform_deferred_access_checks >> (complain) and either return error_mark_node or the spec depending on >> the return value? > > I don't think we need to redo the access check in SFINAE context; we > know that there's an error, so we can just return error_mark_node in > that case. I guess we should change the name of > FNDECL_RECHECK_ACCESS_P to something like FNDECL_HAS_ACCESS_ERRORS to > make it clearer. Ah, very well, everything makes sense now. Thus I'm finishing testing the below (already past the C++ testsuite), Ok if it passes? Thanks, Paolo. /////////////////////// /cp 2012-08-02 Jason Merrill Paolo Carlini PR c++/51213 (again) * pt.c (type_unification_real): Call push_deferring_access_checks / pop_deferring_access_checks around the substitution of default template args. (instantiate_template_1): When the specialization returned by retrieve_specialization has FNDECL_HAS_ACCESS_ERRORS set and we are in a SFINAE context, simply return error_mark_node. * cp-tree.h (FNDECL_RECHECK_ACCESS_P): Rename FNDECL_HAS_ACCESS_ERRORS. /testsuite 2012-08-02 Jason Merrill Paolo Carlini PR c++/51213 (again) * g++.dg/cpp0x/sfinae37.C: Extend. Index: testsuite/g++.dg/cpp0x/sfinae37.C =================================================================== --- testsuite/g++.dg/cpp0x/sfinae37.C (revision 190071) +++ testsuite/g++.dg/cpp0x/sfinae37.C (working copy) @@ -5,6 +5,12 @@ class C { typedef int type; }; +template +struct I; + +template<> +struct I<2> { }; + template auto f(int) -> char; @@ -13,6 +19,10 @@ auto f(...) -> char (&)[2]; static_assert(sizeof(f(0)) == 2, "Ouch"); +typedef int testf[sizeof(f(0)) == 2 ? 1 : -1]; + +I(0))> vf; + template auto g(int) -> decltype(typename T::type(), char()); @@ -20,3 +30,7 @@ template auto g(...) -> char (&)[2]; static_assert(sizeof(g(0)) == 2, "Ouch"); + +typedef int testg[sizeof(g(0)) == 2 ? 1 : -1]; + +I(0))> vg; Index: cp/pt.c =================================================================== --- cp/pt.c (revision 190071) +++ cp/pt.c (working copy) @@ -14363,8 +14363,13 @@ instantiate_template_1 (tree tmpl, tree orig_args, if (spec != NULL_TREE) { - if (FNDECL_RECHECK_ACCESS_P (spec) && (complain & tf_error)) - recheck_decl_substitution (spec, gen_tmpl, targ_ptr); + if (FNDECL_HAS_ACCESS_ERRORS (spec)) + { + if (complain & tf_error) + recheck_decl_substitution (spec, gen_tmpl, targ_ptr); + else + return error_mark_node; + } return spec; } @@ -14426,7 +14431,7 @@ instantiate_template_1 (tree tmpl, tree orig_args, { /* Remember to reinstantiate when we're out of SFINAE so the user can see the errors. */ - FNDECL_RECHECK_ACCESS_P (fndecl) = true; + FNDECL_HAS_ACCESS_ERRORS (fndecl) = true; } return error_mark_node; } @@ -15122,9 +15127,11 @@ type_unification_real (tree tparms, location_t save_loc = input_location; if (DECL_P (parm)) input_location = DECL_SOURCE_LOCATION (parm); + push_deferring_access_checks (dk_no_deferred); arg = tsubst_template_arg (arg, targs, complain, NULL_TREE); arg = convert_template_argument (parm, arg, targs, complain, i, NULL_TREE); + pop_deferring_access_checks (); input_location = save_loc; if (arg == error_mark_node) return 1; Index: cp/cp-tree.h =================================================================== --- cp/cp-tree.h (revision 190071) +++ cp/cp-tree.h (working copy) @@ -729,10 +729,10 @@ 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) \ +#define TINFO_HAS_ACCESS_ERRORS(NODE) \ (TREE_LANG_FLAG_0 (TEMPLATE_INFO_CHECK (NODE))) -#define FNDECL_RECHECK_ACCESS_P(NODE) \ - (TINFO_RECHECK_ACCESS_P (DECL_TEMPLATE_INFO (NODE))) +#define FNDECL_HAS_ACCESS_ERRORS(NODE) \ + (TINFO_HAS_ACCESS_ERRORS (DECL_TEMPLATE_INFO (NODE))) struct GTY(()) tree_template_info { struct tree_common common;