From patchwork Thu Apr 16 17:53:31 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Palka X-Patchwork-Id: 1271820 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=YtE4ICQw; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4936KL1hbFz9sWJ for ; Fri, 17 Apr 2020 03:53:42 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id AE8C6385C426; Thu, 16 Apr 2020 17:53:39 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org AE8C6385C426 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1587059619; bh=GtBwz17KToUl4SuTTMRGSDT7+x4zu5wi3VjW9+66Hp8=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=YtE4ICQwnERPExL3Uu/Es3gTyNAnw6LLy4mgNFsC7V9nQFQBcl9pDu+F0U2J/WyVR vXiNPA/1dykzvwBjJnaUHEfMneKcIqh5lWwcw15lYUTJu+amUxE1BAwqwVfRfd/yW8 osNoX+IDmhFpMwlDTd7sCQBTUp5zIyGdet1IZVpE= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) by sourceware.org (Postfix) with ESMTP id A1756385B835 for ; Thu, 16 Apr 2020 17:53:37 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org A1756385B835 Received: from mail-qk1-f199.google.com (mail-qk1-f199.google.com [209.85.222.199]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-309-OpJqCml2P0C1syg4Q2dAuw-1; Thu, 16 Apr 2020 13:53:35 -0400 X-MC-Unique: OpJqCml2P0C1syg4Q2dAuw-1 Received: by mail-qk1-f199.google.com with SMTP id a187so10697061qkg.18 for ; Thu, 16 Apr 2020 10:53:35 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=yeek2of6okv51sP7boRJWNcJ80weYwhnCus19dVOci8=; b=U+RsuaxcLGeEQWBoVffsZnZxTNWehrVl3ujjaDuipYwduEeFX6C+ftUTnJWtsJVgep akeEvDb5DEnIsZJcgs3XNrE6zFj3e3STKOfeWmi2UkFU7glppITaFEkbBf7FCQC/OlV7 hvuFGHwuH5R5j3fhhoqcvLGJb9ycWXs61pnOmEH6vrAzHT2i5DoU4GAKhOEgvdUbCG8k Mcr3IVEAdHvyTCGMUCw9zPw1V5A3+dMq8eBa73Uav0petB/VQq93883BCVlw4eWl21Bi 779j5gfQnVDpok0IZrvCbqctKf3sR6lg/jo+ksbih6SvvAALup2By7aHqcMXSG5PQAld W1yw== X-Gm-Message-State: AGi0PuZHAXgwJY/KYp8KO5TcxiD5XRtA1B/ThC5aVrxcD7JGUpMgqSPp BkjxG7GzzM5sgpsXpH6p1qXJrOoS8fVervWpmU7icPbRJ7bFuGsC2YVZs1IsVGH84utYf7xXzRq rU6O78OarBZmfDC8tZA== X-Received: by 2002:ac8:c48:: with SMTP id l8mr27561473qti.61.1587059614974; Thu, 16 Apr 2020 10:53:34 -0700 (PDT) X-Google-Smtp-Source: APiQypKHczYKGuhL55IuNhiiT1chz+TTgLHs/G+sVgGROV8wFdWeDJd9oAqvmFmPzCWOYTcuEkp5ow== X-Received: by 2002:ac8:c48:: with SMTP id l8mr27561449qti.61.1587059614688; Thu, 16 Apr 2020 10:53:34 -0700 (PDT) Received: from localhost.localdomain (ool-457d493a.dyn.optonline.net. [69.125.73.58]) by smtp.gmail.com with ESMTPSA id y9sm15916883qtc.12.2020.04.16.10.53.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Apr 2020 10:53:34 -0700 (PDT) To: gcc-patches@gcc.gnu.org Subject: [PATCH] c++: Non-type-dependent variadic lambda init-capture [PR94483] Date: Thu, 16 Apr 2020 13:53:31 -0400 Message-Id: <20200416175331.2019448-1-ppalka@redhat.com> X-Mailer: git-send-email 2.26.1.107.gefe3874640 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-28.5 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Patrick Palka via Gcc-patches From: Patrick Palka Reply-To: Patrick Palka Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" In this PR (which I think is misclassified as ice-on-invalid instead of ice-on-valid), we're ICEing on a use of an 'int... a' template parameter pack as part of the variadic lambda init-capture [...z=a]. The unexpected thing about this variadic init-capture is that it is not type-dependent, and so when we call do_auto_deduction from lambda_capture_field_type it actually resolves its type to 'int' instead of exiting early like it would do for a type-dependent variadic initializer. This later confuses add_capture which, according to one of its comments, assumes that 'type' is always 'auto' for a variadic init-capture. The simplest fix, and the approach that this patch takes, seems to be to avoid doing auto deduction in lambda_capture_field_type when the initializer uses parameter packs, so that we always return 'auto' even in the non-type-dependent case. Passes 'make check-c++', does this look OK to commit after full bootstrap/regtesting? gcc/cp/ChangeLog: PR c++/94483 * lambda.c (lambda_capture_field_type): Avoid doing auto deduction if the explicit initializer has parameter packs. gcc/testsuite/ChangeLog: PR c++/94483 * g++.dg/cpp2a/lambda-pack-init5.C: New test. --- gcc/cp/lambda.c | 5 ++++- gcc/testsuite/g++.dg/cpp2a/lambda-pack-init5.C | 18 ++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/cpp2a/lambda-pack-init5.C diff --git a/gcc/cp/lambda.c b/gcc/cp/lambda.c index 4f39f99756b..b55c2f85d27 100644 --- a/gcc/cp/lambda.c +++ b/gcc/cp/lambda.c @@ -223,7 +223,10 @@ lambda_capture_field_type (tree expr, bool explicit_init_p, /* Add the reference now, so deduction doesn't lose outermost CV qualifiers of EXPR. */ type = build_reference_type (type); - type = do_auto_deduction (type, expr, auto_node); + if (uses_parameter_packs (expr)) + /* Stick with 'auto' even if the type could be deduced. */; + else + type = do_auto_deduction (type, expr, auto_node); } else if (!is_this && type_dependent_expression_p (expr)) { diff --git a/gcc/testsuite/g++.dg/cpp2a/lambda-pack-init5.C b/gcc/testsuite/g++.dg/cpp2a/lambda-pack-init5.C new file mode 100644 index 00000000000..492fc479e94 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp2a/lambda-pack-init5.C @@ -0,0 +1,18 @@ +// PR c++/94483 +// { dg-do compile { target c++2a } } + +template constexpr auto x1 + = [...z = -a] (auto F) { return F(z...); }; + +template constexpr auto x2 + = [&...z = a] (auto F) { return F(z...); }; + +template constexpr auto x3 + = [z = -a] (auto F) { return F(z); }; // { dg-error "packs not expanded" } + + +constexpr auto sum = [] (auto... xs) { return (xs + ... + 0); }; +const int y1 = 1, y2 = 2, y3 = 3; + +static_assert(x1<1,2,3>(sum) == -6); +static_assert(x2(sum) == 6);