From patchwork Fri Aug 3 15:54:35 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 953286 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-483117-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="EKAJ/t2I"; dkim-atps=neutral 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 41hs7L2S0zz9ryn for ; Sat, 4 Aug 2018 01:54:53 +1000 (AEST) 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:mime-version :content-type; q=dns; s=default; b=ASoqu0FUw3pW8x0ONCT7csxa71yXn gkkEzVd79DJo+DZbDtjm9rbOd0H4WLE1zwZnbALgKjUe9N6qxHyJ+N5WWYbLhhgE 9aiaO99vFGvtSSocNq+S2IXYc1KGPJwM31d/oO8l6QlzOBgY8c8lrBiAb4+llAKY qCOB5rQtq2nwwI= 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:mime-version :content-type; s=default; bh=0WazbztJCPopCh/cuYEh9oddH+M=; b=EKA J/t2I6dTAxWFrNvfP0oi1F5hukWAdtm+ViJWOW10LkputOIldZds7KS/q+47GbeA IkLhz1o46U7vdNE5xLroeSOMop1iae/LJg42P0SuyTLcBYJunchjssCkR0iHT751 fs4lKuWHEzsOBueZHTnmWPANFhzH+YMC5nqlyguY= Received: (qmail 67764 invoked by alias); 3 Aug 2018 15:54:45 -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 67755 invoked by uid 89); 3 Aug 2018 15:54:45 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-11.9 required=5.0 tests=BAYES_00, GIT_PATCH_2, GIT_PATCH_3, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=HTo:D*acm.org, specializations 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; Fri, 03 Aug 2018 15:54:41 +0000 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.25]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id EABC130832ED; Fri, 3 Aug 2018 15:54:39 +0000 (UTC) Received: from tucnak.zalov.cz (ovpn-117-71.ams2.redhat.com [10.36.117.71]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 640982010CBF; Fri, 3 Aug 2018 15:54:39 +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 w73FsbuW004016; Fri, 3 Aug 2018 17:54:37 +0200 Received: (from jakub@localhost) by tucnak.zalov.cz (8.15.2/8.15.2/Submit) id w73FsZht001162; Fri, 3 Aug 2018 17:54:35 +0200 Date: Fri, 3 Aug 2018 17:54:35 +0200 From: Jakub Jelinek To: Nathan Sidwell , Jason Merrill Cc: gcc-patches@gcc.gnu.org Subject: [C++ PATCH] Fix tsubst of structured bindings (PR c++/86836) Message-ID: <20180803155435.GQ17988@tucnak> Reply-To: Jakub Jelinek MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.9.2 (2017-12-15) X-IsSubscribed: yes Hi! As mentioned in the PR, for valid structured bindings this patch should be unnecessary, because the identifiers from the structured binding shouldn't be used in the initializer of the structured binding, but for invalid source it can matter. When tsubst_init is called before tsubst_decomp_names, the local specializations for the decomp id VAR_DECLs aren't created and so the tsubst of those VAR_DECLs gives the PARM_DECL in this testcase, or something else unrelated to the decomp. Fixed by doing tsubst_decomp_names first, then tsubst_init the initializer and then the rest. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk and 8.3 after a while? 2018-08-03 Jakub Jelinek PR c++/86836 * pt.c (tsubst_expr): For structured bindings, call tsubst_decomp_names before tsubst_init, not after it. * g++.dg/cpp1z/decomp46.C: New test. Jakub --- gcc/cp/pt.c.jj 2018-08-03 11:36:25.550755429 +0200 +++ gcc/cp/pt.c 2018-08-03 11:48:51.144567965 +0200 @@ -16740,7 +16740,17 @@ tsubst_expr (tree t, tree args, tsubst_f else { int const_init = false; + unsigned int cnt = 0; + tree first = NULL_TREE, ndecl = error_mark_node; maybe_push_decl (decl); + + if (VAR_P (decl) + && DECL_DECOMPOSITION_P (decl) + && TREE_TYPE (pattern_decl) != error_mark_node) + ndecl = tsubst_decomp_names (decl, pattern_decl, args, + complain, in_decl, &first, + &cnt); + if (VAR_P (decl) && DECL_PRETTY_FUNCTION_P (decl)) { @@ -16756,23 +16766,14 @@ tsubst_expr (tree t, tree args, tsubst_f if (VAR_P (decl)) const_init = (DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (pattern_decl)); - if (VAR_P (decl) - && DECL_DECOMPOSITION_P (decl) - && TREE_TYPE (pattern_decl) != error_mark_node) - { - unsigned int cnt; - tree first; - tree ndecl - = tsubst_decomp_names (decl, pattern_decl, args, - complain, in_decl, &first, &cnt); - if (ndecl != error_mark_node) - cp_maybe_mangle_decomp (ndecl, first, cnt); - cp_finish_decl (decl, init, const_init, NULL_TREE, 0); - if (ndecl != error_mark_node) - cp_finish_decomp (ndecl, first, cnt); - } - else - cp_finish_decl (decl, init, const_init, NULL_TREE, 0); + + if (ndecl != error_mark_node) + cp_maybe_mangle_decomp (ndecl, first, cnt); + + cp_finish_decl (decl, init, const_init, NULL_TREE, 0); + + if (ndecl != error_mark_node) + cp_finish_decomp (ndecl, first, cnt); } } } --- gcc/testsuite/g++.dg/cpp1z/decomp46.C.jj 2018-08-03 12:00:10.524066454 +0200 +++ gcc/testsuite/g++.dg/cpp1z/decomp46.C 2018-08-03 11:59:49.925018174 +0200 @@ -0,0 +1,25 @@ +// PR c++/86836 +// { dg-do compile { target c++11 } } +// { dg-options "" } + +struct A { + int operator*(); + void operator++(); + bool operator!=(A); +}; +template class map { +public: + A begin(); + A end(); +}; + +template void mergemap(map orig, map toadd) { + for (auto p : toadd) + auto [orig] = orig; // { dg-error "use of 'orig' before deduction of 'auto'" } +} // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 } + +int +main() { + map x, y; + mergemap(x, y); +}