From patchwork Mon Apr 30 23:37:39 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Carlini X-Patchwork-Id: 155979 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 8BA60B6F9F for ; Tue, 1 May 2012 09:38:22 +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=1336433902; 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=7V49Kse7mAGOk2YRv2oo/H8Vl8Q=; b=ubIJAnlGcpusxHdaFN8JeBt/MYY86L8uYTWqVAH8WipUjTND+E55xjdJZFSbP+ gjnieblOS8p84zTYWRkHX8bvhPE3fwyPmxOjCLsc/qcyJClUqRMGgKPwS9GfmPzu 3gaDjmsX4aR+1ZEGu/jDI5/TGirRdlP2VoRzNnvZ2DggM= 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=bYNjvNx8lQCry60j640O07GqsTOZMVum+u1mopyaQdPPLfEWYu4V2xEfWrKp0c LdIRmf/eBfAw5sfOgmY6q8K6M1z/z2xPp8XwWu9tDoHPHrhL83dJHbXVBw4DkbuB jDUYWbV4oqPpe65twnEQc9YfZ6Ht3/xGMAXD+6yovMPs4=; Received: (qmail 1066 invoked by alias); 30 Apr 2012 23:38:19 -0000 Received: (qmail 1055 invoked by uid 22791); 30 Apr 2012 23:38:18 -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_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; Mon, 30 Apr 2012 23:38:05 +0000 Received: from acsinet22.oracle.com (acsinet22.oracle.com [141.146.126.238]) by acsinet15.oracle.com (Sentrion-MTA-4.2.2/Sentrion-MTA-4.2.2) with ESMTP id q3UNc2J7027792 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 30 Apr 2012 23:38:03 GMT Received: from acsmt357.oracle.com (acsmt357.oracle.com [141.146.40.157]) by acsinet22.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id q3UNc2mZ014076 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Mon, 30 Apr 2012 23:38:02 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 q3UNc1ij025904; Mon, 30 Apr 2012 18:38:01 -0500 Received: from [192.168.1.4] (/79.52.240.119) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 30 Apr 2012 16:38:01 -0700 Message-ID: <4F9F2243.7000802@oracle.com> Date: Tue, 01 May 2012 01:37:39 +0200 From: Paolo Carlini User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:12.0) Gecko/20120421 Thunderbird/12.0 MIME-Version: 1.0 To: Jason Merrill CC: "gcc-patches@gcc.gnu.org" Subject: Re: [RFH / Patch] PR 51222 References: <4F9B4B10.7090409@oracle.com> <4F9B62F0.5090202@redhat.com> <4F9BD0B8.4030005@oracle.com> <4F9CB2C9.3060700@redhat.com> <4F9D6180.4030408@oracle.com> <4F9EC605.2050703@redhat.com> In-Reply-To: <4F9EC605.2050703@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 again, > On 04/29/2012 11:42 AM, Paolo Carlini wrote: >>> This might just be a matter of calling for_each_template_parm and >>> returning 1 if we see any template parameter. >> Good. Today I quickly tried something along these lines (see 'p' >> attachment) and got some fails: > > Ah, well. I guess for_each_template_parm doesn't look at the types of > declarations. Just a few moments ago I noticed something interesting: if a NULL FN is passed to for_each_template_parm, it assumes a function which always returns 1, what we want when just searching for the first occurrence. Now, in practice, *no* front-code calls it like this! Thus, if we want, it's safe to tweak / extend for_each_template_parm_r for our purposes when !fn And indeed, the attached passes the testsuite with no regressions ;) I also want to remark that there is this kind of comment: case INDIRECT_REF: case COMPONENT_REF: /* If there's no type, then this thing must be some expression involving template parameters. */ if (!fn && !TREE_TYPE (t)) return error_mark_node; + else if (!fn && for_each_template_parm (TREE_TYPE (t), fn, + data, pfd->visited, + pfd->include_nondeduced_p)) + return error_mark_node; which, how can I say, appears to "support" the idea of tweaking / extending the code in the direction we like. Thus, my question would be: is something like the below in the right direction? The alternate possibility I can see, would be basically redoing a slightly slimmed version of for_each_template_parm specialized for our needs (a few less conditionals) Thanks! Paolo. //////////////////////////// Index: pt.c =================================================================== --- pt.c (revision 187001) +++ pt.c (working copy) @@ -7861,6 +7861,10 @@ for_each_template_parm_r (tree *tp, int *walk_subt && for_each_template_parm (DECL_CONTEXT (t), fn, data, pfd->visited, pfd->include_nondeduced_p)) return error_mark_node; + if (!fn && TREE_TYPE (t) + && for_each_template_parm (TREE_TYPE(t), fn, data, + pfd->visited, pfd->include_nondeduced_p)) + return error_mark_node; break; case BOUND_TEMPLATE_TEMPLATE_PARM: @@ -7905,6 +7909,11 @@ for_each_template_parm_r (tree *tp, int *walk_subt (TREE_TYPE (t)), fn, data, pfd->visited, pfd->include_nondeduced_p)) return error_mark_node; + else if (!fn && TREE_TYPE (t) + && for_each_template_parm (TREE_TYPE (t), fn, + data, pfd->visited, + pfd->include_nondeduced_p)) + return error_mark_node; break; case INDIRECT_REF: @@ -7913,6 +7922,10 @@ for_each_template_parm_r (tree *tp, int *walk_subt involving template parameters. */ if (!fn && !TREE_TYPE (t)) return error_mark_node; + else if (!fn && for_each_template_parm (TREE_TYPE (t), fn, + data, pfd->visited, + pfd->include_nondeduced_p)) + return error_mark_node; break; case MODOP_EXPR: @@ -19744,6 +19757,29 @@ type_dependent_expression_p (tree expression) return (dependent_type_p (TREE_TYPE (expression))); } +/* Returns TRUE if the EXPRESSION is instantiation-dependent, in the + sense defined by the ABI: + + "An expression is instantiation-dependent if it is type-dependent + or value-dependent, or it has a subexpression that is type-dependent + or value-dependent." */ + +bool +instantiation_dependent_expression_p (tree expression) +{ + if (!processing_template_decl) + return false; + + if (expression == error_mark_node) + return false; + + if (!TREE_TYPE (expression)) + return true; + + return for_each_template_parm (expression, NULL, NULL, NULL, + /*include_nondeduced_p=*/true); +} + /* Like type_dependent_expression_p, but it also works while not processing a template definition, i.e. during substitution or mangling. */ Index: semantics.c =================================================================== --- semantics.c (revision 187001) +++ semantics.c (working copy) @@ -5168,8 +5168,7 @@ finish_decltype_type (tree expr, bool id_expressio return error_mark_node; } - /* FIXME instantiation-dependent */ - if (type_dependent_expression_p (expr) + if (instantiation_dependent_expression_p (expr) /* In a template, a COMPONENT_REF has an IDENTIFIER_NODE for op1 even if it isn't dependent, so that we can check access control at instantiation time, so defer the decltype as well (PR 42277). */ Index: cp-tree.h =================================================================== --- cp-tree.h (revision 187001) +++ cp-tree.h (working copy) @@ -5363,6 +5363,7 @@ extern bool any_type_dependent_arguments_p (c extern bool any_type_dependent_elements_p (const_tree); extern bool type_dependent_expression_p_push (tree); extern bool value_dependent_expression_p (tree); +extern bool instantiation_dependent_expression_p(tree); extern bool any_value_dependent_elements_p (const_tree); extern bool dependent_omp_for_p (tree, tree, tree, tree); extern tree resolve_typename_type (tree, bool);