From patchwork Wed Jan 17 15:38:25 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathan Sidwell X-Patchwork-Id: 862313 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-471484-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="qpy1xi+z"; 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 3zMB814BWFz9sDB for ; Thu, 18 Jan 2018 02:38:40 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:to :from:subject:message-id:date:mime-version:content-type; q=dns; s=default; b=v10tlRnqfGdLodnz2wwSYCtcAPtNG/OY8kzqQpgG+i9kwHuDxB D3wJr428ykS9ExyEXzW4rQ4IG4AsDD3tITybS2QyiZKgl39qPrzwk2cEJPETC8Fw dokakUclZav6ipA3Cb+ZQTquY8KX95fjxQeFVI5KcDGkb7fx3VgD9lHY8= 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:to :from:subject:message-id:date:mime-version:content-type; s= default; bh=A6YCVEpzZWig+WGaOkpP7igQRbU=; b=qpy1xi+zuNODtidE92G5 i1a0c7aOMau9Y1CeGcMOz4WbineF3YoOZwJs6IMaMyt1HhjLAFP8j8hdPxBe9KWA ou3KvOKSCuqhbXH9kknhMEvxITo1POo8alnRnt1h4hu1XTrJ2qdNQ9kbfVySPZEQ Ek+QE6l1xhNORcpcFRzTjC8= Received: (qmail 68905 invoked by alias); 17 Jan 2018 15:38:33 -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 68891 invoked by uid 89); 17 Jan 2018 15:38:32 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-11.1 required=5.0 tests=BAYES_00, FREEMAIL_FROM, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy=delegate, Hx-languages-length:2949 X-HELO: mail-yw0-f176.google.com Received: from mail-yw0-f176.google.com (HELO mail-yw0-f176.google.com) (209.85.161.176) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 17 Jan 2018 15:38:29 +0000 Received: by mail-yw0-f176.google.com with SMTP id x24so8325975ywj.0 for ; Wed, 17 Jan 2018 07:38:29 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:to:from:subject:message-id:date :user-agent:mime-version:content-language; bh=KvCY3JQW9h+eaqRjlOEbUxkFSL3i9591urEL33lWsiE=; b=MsMBPl0l7h8GB5YCNBn8tAlsDmBjV1W+ycXZxudIy4StOnzM4yc1JEcMUZRJDwKm8w TJpQyQepmrpRRiFHV3+TREONtLA8qfoc7NzO0Zq98wjT7c27frfcUwJbYcZbLsDud6uT cTEVBH87nDNPGWjW+QKz4oi6KBqfr2875pecODOpkB3AsYVmVN6HdoqQMyAK38rVn3In zupfCaiPHtYt+jmsmY6i22O9s/8X19dek+/KHVI27MeJQzztq0szY4jQx0MNaieU2kkr yqjzjGBNn1EouSRcWjPC7KOAuRaEWHt4p8ee5Bv52dtIevm/Gwq7rX5CDJluVg4qyqqD 6niA== X-Gm-Message-State: AKwxyteAiNcOfW5tWhAI52SrMnVl4XQAh+YCT60ItAV6CcMUwlXB1aw8 iswtPNJl9TRxHTY6xqmNrt0= X-Google-Smtp-Source: ACJfBouQLhccvs9H+Jee5QJkux3FfTg+UeTpKTYjr0OJaAHVzMemGSfRQUMbgo6I2/Iq3dI49Yi62Q== X-Received: by 10.129.125.134 with SMTP id y128mr2973702ywc.146.1516203507524; Wed, 17 Jan 2018 07:38:27 -0800 (PST) Received: from ?IPv6:2620:10d:c0a3:20fb:7500:e7fb:4a6f:2254? ([2620:10d:c091:200::2:280f]) by smtp.googlemail.com with ESMTPSA id v128sm1928517ywd.22.2018.01.17.07.38.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 17 Jan 2018 07:38:26 -0800 (PST) To: GCC Patches From: Nathan Sidwell Subject: [C++/83739] bogus error tsubsting range for in generic lambda Message-ID: <2c8abf4d-1600-c067-73df-90881ceb5758@acm.org> Date: Wed, 17 Jan 2018 10:38:25 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.5.2 MIME-Version: 1.0 When a generic lambda contains a range_for, and we're instantiating the containing function, we must rebuild a range_for. We should only convert to a regular for when tsubsting the resulting generic lambda itself. This patch looks at processing_template_decl to determine that. Applying to trunk. nathan 2018-01-17 Nathan Sidwell PR c++/83739 * pt.c (tsubst_expr) : Rebuild a range_for if this not a final instantiation. PR c++/83739 * g++.dg/cpp1y/pr83739.C: New. Index: cp/pt.c =================================================================== --- cp/pt.c (revision 256794) +++ cp/pt.c (working copy) @@ -16153,26 +16153,40 @@ tsubst_expr (tree t, tree args, tsubst_f case RANGE_FOR_STMT: { + /* Construct another range_for, if this is not a final + substitution (for inside inside a generic lambda of a + template). Otherwise convert to a regular for. */ tree decl, expr; - stmt = begin_for_stmt (NULL_TREE, NULL_TREE); + stmt = (processing_template_decl + ? begin_range_for_stmt (NULL_TREE, NULL_TREE) + : begin_for_stmt (NULL_TREE, NULL_TREE)); decl = RANGE_FOR_DECL (t); decl = tsubst (decl, args, complain, in_decl); maybe_push_decl (decl); expr = RECUR (RANGE_FOR_EXPR (t)); - const unsigned short unroll - = RANGE_FOR_UNROLL (t) ? tree_to_uhwi (RANGE_FOR_UNROLL (t)) : 0; + + tree decomp_first = NULL_TREE; + unsigned decomp_cnt = 0; if (VAR_P (decl) && DECL_DECOMPOSITION_P (decl)) + decl = tsubst_decomp_names (decl, RANGE_FOR_DECL (t), args, + complain, in_decl, + &decomp_first, &decomp_cnt); + + if (processing_template_decl) { - unsigned int cnt; - tree first; - decl = tsubst_decomp_names (decl, RANGE_FOR_DECL (t), args, - complain, in_decl, &first, &cnt); - stmt = cp_convert_range_for (stmt, decl, expr, first, cnt, - RANGE_FOR_IVDEP (t), unroll); + RANGE_FOR_IVDEP (stmt) = RANGE_FOR_IVDEP (t); + RANGE_FOR_UNROLL (stmt) = RANGE_FOR_UNROLL (t); + finish_range_for_decl (stmt, decl, expr); } else - stmt = cp_convert_range_for (stmt, decl, expr, NULL_TREE, 0, - RANGE_FOR_IVDEP (t), unroll); + { + unsigned short unroll = (RANGE_FOR_UNROLL (t) + ? tree_to_uhwi (RANGE_FOR_UNROLL (t)) : 0); + stmt = cp_convert_range_for (stmt, decl, expr, + decomp_first, decomp_cnt, + RANGE_FOR_IVDEP (t), unroll); + } + bool prev = note_iteration_stmt_body_start (); RECUR (RANGE_FOR_BODY (t)); note_iteration_stmt_body_end (prev); Index: testsuite/g++.dg/cpp1y/pr83739.C =================================================================== --- testsuite/g++.dg/cpp1y/pr83739.C (revision 0) +++ testsuite/g++.dg/cpp1y/pr83739.C (working copy) @@ -0,0 +1,16 @@ +// { dg-do compile { target c++14 } } + +// PR 83739, deduced range-for in lambda in template + +template void f() +{ + int x[2]; + auto delegate = [](auto & foo) + { + for (auto bar : foo); + }; + delegate(x); +} +int main() { + f(); +}