From patchwork Mon Sep 12 17:50:41 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 1677009 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.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+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: legolas.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=vX1sIn4U; 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 ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4MRDfj5Sj6z1yhR for ; Tue, 13 Sep 2022 03:51:08 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 92B1A393BA5A for ; Mon, 12 Sep 2022 17:51:05 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 92B1A393BA5A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1663005065; bh=cJ4f9FYdvV0+o/ELD1wGAanHOA+jUmw2sp8WuH6yI44=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=vX1sIn4U7MTbcenQcp2Wetc2NR49m5JQJzq8z/QqcsLZcZcs51iLZjBMYEGdLvEV4 4g4W2l/aClbbUExXi5BU5icvxvF9E53XOztl5xfGG5Hk/BqOlZn8kBBLNBPqVITpPs mzNYL06SB04SfnVd0tD0/excxybz8otL63e7QTPs= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id B0CAE385694E for ; Mon, 12 Sep 2022 17:50:46 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org B0CAE385694E Received: from mail-qt1-f198.google.com (mail-qt1-f198.google.com [209.85.160.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-30-bgXnYgK3NpusdOgSL_mNIA-1; Mon, 12 Sep 2022 13:50:45 -0400 X-MC-Unique: bgXnYgK3NpusdOgSL_mNIA-1 Received: by mail-qt1-f198.google.com with SMTP id ci6-20020a05622a260600b0034370b6f5d6so7856982qtb.14 for ; Mon, 12 Sep 2022 10:50:45 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date; bh=cJ4f9FYdvV0+o/ELD1wGAanHOA+jUmw2sp8WuH6yI44=; b=DZUSGAPOX6C+BV7f2VnzIs/b34hCXQkr05dNTXY5Z66UXDN/ac9hbpauYM3cLMyfj3 u8IFlMLzrOYhREogYVka6dEuu6OSdOmyH7t98UbhFBRMvy/LTQeEHxsRgKr6T3J04I/o S9wN04ajzfrqvF3N59W49RSar0IEI4I2Ii9VxRBsHPAjqlKTL6h9yl3tjvqW7ZVzvdrV ImjRFSE8k0VNZVl8wll/qkgtp5Zg++S3Quaj3/gLWAT77EYlNmgoDLF2We3pMMk5LsI8 KSqgQPPSqu2XAAD4jC4t7xgFWgeX6pNyYo/EOIiyydrTbAqk0z4C3QI+RwesPo9nkyaH X1UA== X-Gm-Message-State: ACgBeo3D/KV98pJVvU3AyQY89yF3/1uqZJE6AHtGicWLGybQ/sz7cXtS cdY570ujWi3wSyELR6F28KRIyiY+dhIJdqhc8B6VaILx4XbAahONdq/QwpHtpGtSZSkqZEpuh10 cdudnRB4qluMROFntv4dyAs77ubnozbJWlMI66qAoVKABMWk8IhUO8Qwxv69YpjUVZw== X-Received: by 2002:a05:620a:2956:b0:6ce:60f5:d887 with SMTP id n22-20020a05620a295600b006ce60f5d887mr382987qkp.303.1663005044433; Mon, 12 Sep 2022 10:50:44 -0700 (PDT) X-Google-Smtp-Source: AA6agR5lAJSowv1tSsonu+Co10C5Ni0k3TqRnWRmI2vcyGMqTeF7rNIoF2v1OaPBNhxGOcnsrqBYdQ== X-Received: by 2002:a05:620a:2956:b0:6ce:60f5:d887 with SMTP id n22-20020a05620a295600b006ce60f5d887mr382971qkp.303.1663005044021; Mon, 12 Sep 2022 10:50:44 -0700 (PDT) Received: from barrymore.redhat.com (130-44-159-43.s15913.c3-0.arl-cbr1.sbo-arl.ma.cable.rcncustomer.com. [130.44.159.43]) by smtp.gmail.com with ESMTPSA id j25-20020ac86659000000b0035ba5af2a75sm6531691qtp.16.2022.09.12.10.50.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Sep 2022 10:50:43 -0700 (PDT) To: gcc-patches@gcc.gnu.org Subject: [PATCH] c++: lambda capture of array with deduced bounds [PR106567] Date: Mon, 12 Sep 2022 13:50:41 -0400 Message-Id: <20220912175041.3406947-1-jason@redhat.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-13.2 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) 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: Jason Merrill via Gcc-patches From: Jason Merrill Reply-To: Jason Merrill Cc: Ville Voutilainen Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" We can't use the type of an array variable directly if we haven't deduced its length yet. Tested x86_64-pc-linux-gnu, applying to trunk. PR c++/106567 gcc/cp/ChangeLog: * lambda.cc (type_deducible_expression_p): Check array_of_unknown_bound_p. gcc/testsuite/ChangeLog: * g++.dg/cpp0x/lambda/lambda-array4.C: New test. --- gcc/cp/lambda.cc | 1 + .../g++.dg/cpp0x/lambda/lambda-array4.C | 29 +++++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 gcc/testsuite/g++.dg/cpp0x/lambda/lambda-array4.C base-commit: 8ef5fa4c56c82dfbd6e8fc5e4e08c4be843abc3e diff --git a/gcc/cp/lambda.cc b/gcc/cp/lambda.cc index 3fb98a98057..3ee1fe9489e 100644 --- a/gcc/cp/lambda.cc +++ b/gcc/cp/lambda.cc @@ -198,6 +198,7 @@ type_deducible_expression_p (tree expr) tree t = non_reference (TREE_TYPE (expr)); return (t && TREE_CODE (t) != TYPE_PACK_EXPANSION && !WILDCARD_TYPE_P (t) && !LAMBDA_TYPE_P (t) + && !array_of_unknown_bound_p (t) && !type_uses_auto (t)); } diff --git a/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-array4.C b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-array4.C new file mode 100644 index 00000000000..94ec7f8457e --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-array4.C @@ -0,0 +1,29 @@ +// PR c++/106567 +// { dg-do compile { target c++11 } } + +template +void urgh() +{ + const V x[] = {V(0), V(1), V(2), V(0)}; + + [&]() { + for (auto& v : x) {} + }(); +} + +void no_urgh() +{ + using V = int; + + const V x[] = {V(0), V(1), V(2), V(0)}; + + [&]() { + for (auto& v : x) {} + }(); +} + +int main() +{ + no_urgh(); + urgh(); +}