From patchwork Tue Apr 11 17:13:22 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 749566 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]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3w2YYM0q7tz9sNZ for ; Wed, 12 Apr 2017 03:13:42 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="dun7J3cd"; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:cc:subject:message-id:reply-to:references:mime-version :content-type:in-reply-to; q=dns; s=default; b=W/osCHOPaLMI7SM5K 4IBsoWCMG5BGiERX2SmRAlZ1VJ4Mt4k7z8Njy7J07uYoevjkXErByHmYJm0XjQga kGQBh1I8Ns6XWrPnabV9FoGd0tjW7LviOXK6tdFPJi+sCnrgEQxLdpDyFYGl6VR7 j6yXvU1PvtfBii8jF5FeXVdZ7Q= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:cc:subject:message-id:reply-to:references:mime-version :content-type:in-reply-to; s=default; bh=Ze0/+HIhc/Hc9rej47oESZu /z9o=; b=dun7J3cdy4F25m8BZz1sqlGda2vtt8IFu9YT/zSXMqIwMzDXcAsA/r3 H77/9VVCfZCRLYrOyHve6QZjYOltyy2NwYe5bQn++M355gDOE7QLSKblqF9mHPxa ql73aMr8oI2F4wnAs+9CpXrGfKySKPI96oi4LIWhwYL/bIb/c1FA= Received: (qmail 52504 invoked by alias); 11 Apr 2017 17:13:28 -0000 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 Received: (qmail 51753 invoked by uid 89); 11 Apr 2017 17:13:27 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-10.9 required=5.0 tests=BAYES_00, GIT_PATCH_2, GIT_PATCH_3, KAM_LAZY_DOMAIN_SECURITY, RP_MATCHES_RCVD, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy= X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 11 Apr 2017 17:13:26 +0000 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7B8D67F6C8 for ; Tue, 11 Apr 2017 17:13:26 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 7B8D67F6C8 Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=jakub@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 7B8D67F6C8 Received: from tucnak.zalov.cz (ovpn-116-29.ams2.redhat.com [10.36.116.29]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 2341160BE2; Tue, 11 Apr 2017 17:13:25 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.15.2/8.15.2) with ESMTP id v3BHDNBx021342; Tue, 11 Apr 2017 19:13:24 +0200 Received: (from jakub@localhost) by tucnak.zalov.cz (8.15.2/8.15.2/Submit) id v3BHDMXr021341; Tue, 11 Apr 2017 19:13:22 +0200 Date: Tue, 11 Apr 2017 19:13:22 +0200 From: Jakub Jelinek To: Jason Merrill Cc: gcc-patches List Subject: [C++ PATCH] Fix decomp ICEs in templates (PR c++/80370, take 3) Message-ID: <20170411171322.GS1809@tucnak> Reply-To: Jakub Jelinek References: <20170410203502.GJ1809@tucnak> <20170411134139.GR1809@tucnak> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20170411134139.GR1809@tucnak> User-Agent: Mutt/1.7.1 (2016-10-04) X-IsSubscribed: yes On Tue, Apr 11, 2017 at 03:41:39PM +0200, Jakub Jelinek wrote: > So like this? Or just type_dependent_expression_p check rather than > both? To answer myself, testing there both type_dependent_expression_p and value_dependent_expression_p for value_expr breaks the lambda-generic-const2.C testcase. So I'll test this instead: 2017-04-11 Jakub Jelinek PR c++/80370 * decl.c (cp_finish_decomp): If processing_template_decl on non-dependent decl, only set TREE_TYPE on the v[i] decls, but don't change their DECL_VALUE_EXPR nor cp_finish_decl them. Instead make sure DECL_VALUE_EXPR is the canonical NULL type ARRAY_REF for tsubst processing. * pt.c (value_dependent_expression_p) : For variables with DECL_VALUE_EXPR, return true if DECL_VALUE_EXPR is type dependent. * g++.dg/cpp1z/decomp28.C: New test. Jakub --- gcc/cp/decl.c.jj 2017-04-10 22:26:56.441388051 +0200 +++ gcc/cp/decl.c 2017-04-11 15:21:24.473163169 +0200 @@ -7473,6 +7473,8 @@ cp_finish_decomp (tree decl, tree first, { TREE_TYPE (v[i]) = eltype; layout_decl (v[i], 0); + if (processing_template_decl) + continue; tree t = unshare_expr (dexp); t = build4_loc (DECL_SOURCE_LOCATION (v[i]), ARRAY_REF, eltype, t, size_int (i), NULL_TREE, @@ -7492,6 +7494,8 @@ cp_finish_decomp (tree decl, tree first, { TREE_TYPE (v[i]) = eltype; layout_decl (v[i], 0); + if (processing_template_decl) + continue; tree t = unshare_expr (dexp); t = build1_loc (DECL_SOURCE_LOCATION (v[i]), i ? IMAGPART_EXPR : REALPART_EXPR, eltype, @@ -7510,6 +7514,8 @@ cp_finish_decomp (tree decl, tree first, { TREE_TYPE (v[i]) = eltype; layout_decl (v[i], 0); + if (processing_template_decl) + continue; tree t = unshare_expr (dexp); convert_vector_to_array_for_subscript (DECL_SOURCE_LOCATION (v[i]), &t, size_int (i)); @@ -7559,8 +7565,9 @@ cp_finish_decomp (tree decl, tree first, SET_DECL_VALUE_EXPR (v[i], NULL_TREE); DECL_HAS_VALUE_EXPR_P (v[i]) = 0; } - cp_finish_decl (v[i], init, /*constexpr*/false, - /*asm*/NULL_TREE, LOOKUP_NORMAL); + if (!processing_template_decl) + cp_finish_decl (v[i], init, /*constexpr*/false, + /*asm*/NULL_TREE, LOOKUP_NORMAL); } } else if (TREE_CODE (type) == UNION_TYPE) @@ -7615,12 +7622,26 @@ cp_finish_decomp (tree decl, tree first, tt = TREE_OPERAND (tt, 0); TREE_TYPE (v[i]) = TREE_TYPE (tt); layout_decl (v[i], 0); - SET_DECL_VALUE_EXPR (v[i], tt); - DECL_HAS_VALUE_EXPR_P (v[i]) = 1; + if (!processing_template_decl) + { + SET_DECL_VALUE_EXPR (v[i], tt); + DECL_HAS_VALUE_EXPR_P (v[i]) = 1; + } i++; } } - if (DECL_NAMESPACE_SCOPE_P (decl)) + if (processing_template_decl) + { + for (unsigned int i = 0; i < count; i++) + if (!DECL_HAS_VALUE_EXPR_P (v[i])) + { + tree a = build_nt (ARRAY_REF, decl, size_int (i), + NULL_TREE, NULL_TREE); + SET_DECL_VALUE_EXPR (v[i], a); + DECL_HAS_VALUE_EXPR_P (v[i]) = 1; + } + } + else if (DECL_NAMESPACE_SCOPE_P (decl)) SET_DECL_ASSEMBLER_NAME (decl, mangle_decomp (decl, v)); } --- gcc/cp/pt.c.jj 2017-04-11 19:06:52.871624849 +0200 +++ gcc/cp/pt.c 2017-04-11 19:10:39.795803274 +0200 @@ -23576,6 +23576,12 @@ value_dependent_expression_p (tree expre || type_dependent_expression_p (DECL_INITIAL (expression)) || value_dependent_expression_p (DECL_INITIAL (expression)))) return true; + if (DECL_HAS_VALUE_EXPR_P (expression)) + { + tree value_expr = DECL_VALUE_EXPR (expression); + if (type_dependent_expression_p (value_expr)) + return true; + } return false; case DYNAMIC_CAST_EXPR: --- gcc/testsuite/g++.dg/cpp1z/decomp28.C.jj 2017-04-11 15:21:24.473163169 +0200 +++ gcc/testsuite/g++.dg/cpp1z/decomp28.C 2017-04-11 15:21:24.473163169 +0200 @@ -0,0 +1,39 @@ +// PR c++/80370 +// { dg-do compile { target c++14 } } +// { dg-options "" } + +namespace std { + template struct tuple_size; + template struct tuple_element; + template struct tuple {}; + template struct tuple_size> { static constexpr int value = 1; }; + template struct tuple_element<0, tuple> { typedef T type; }; + template int& get (tuple); +} + +template +void +foo (std::tuple b) +{ + auto [c] = b; // { dg-warning "decomposition declaration only available with" "" { target c++14_down } } +} + +template +void +bar (std::tuple b) +{ + auto [c] = b; // { dg-warning "decomposition declaration only available with" "" { target c++14_down } } +} + +void +baz (std::tuple b) +{ + foo <5> (b); + bar (b); +} + +int +main () +{ + [](auto) { [](std::tuple b) { auto[c] = b; }; } (0); // { dg-warning "decomposition declaration only available with" "" { target c++14_down } } +}