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: 1171 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5044:0:0:0:0:0 with SMTP id h4csp1987538wrt; Mon, 12 Sep 2022 10:51:35 -0700 (PDT) X-Google-Smtp-Source: AA6agR6oPfLM6pkuKCVIte7Hr9vlWSfEeN6X6o5OKYYQdltvMZ5oyVzklllswXBPM92jfV3WTtLx X-Received: by 2002:a17:907:c1b:b0:775:ba03:1040 with SMTP id ga27-20020a1709070c1b00b00775ba031040mr14848979ejc.723.1663005094873; Mon, 12 Sep 2022 10:51:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663005094; cv=none; d=google.com; s=arc-20160816; b=LtBJtHpgi/MPSYQkHzjyLCu8c2f9dsq8qPvJtfMlY3e1xNSuywLPo7XiRQJbVmzINz BZDQhXtTjHeC1xOuxkgU99ZpSjbY6Io1jb5nghFZbIaR1KOtRQm/+OgmhCefhN5zz9VJ P82rUhVrZfDYO8FdtqltXuASaPRMDEmMqrqAyEpcVnpXA8LFiknPLO/EfnMBiLXtSgeg MDvew/BQcxKptCqGdr5MyQEmibKN9JYL6n4OpsPI4Z/Nq+cc+G7nwBnjrC+GlnztweQo 6XpTMfkuof0LMQBt88NNo0cS9Hh7KT2bXa/rRPixnNwXl4HinSLjeoPXY0Xk+vzMyYeH WqIA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:reply-to:from:list-subscribe:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:message-id:date:subject:to :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=cJ4f9FYdvV0+o/ELD1wGAanHOA+jUmw2sp8WuH6yI44=; b=LsFsRya/VJHppW7VPr3/Bc+Z80T6UVlmgdcqpgf1jb7NSyOfmPmRsfAW/bJk0zssWX +jIbQ0+4LbzYcf3K1NEww6xNoV9YFP6VL/RRcd+2MWValqi5vl0dbD6razdMSelW9UZn 9/fWb+P2VIGcEKsPRyMo4HZSAPgH0ZdCw0hM48X2p+nf0+2nG5YDSEd+LchFUeWAWnfT m5t7Sycp2iOPOn3xl3W4nkkWPKRzcEGjkmles1Qz1hVuuRTzzBZ1+hCW6Nk6Wn/32eoX NbCaKccJPrnxo6mMyT/WCL594dG55/VW67AJKv8IBzlx7GE2x2DNrx2nyNeli8xUxjV7 0MLg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b="uGue/nJF"; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id y19-20020a1709063a9300b00730a5a456e9si6585714ejd.758.2022.09.12.10.51.34 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Sep 2022 10:51:34 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b="uGue/nJF"; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id CB902393BA4A for ; Mon, 12 Sep 2022 17:51:28 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org CB902393BA4A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1663005088; 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=uGue/nJF6TWQYmmthgeAveTmi4QQ3d41TIhCp0vkTxc7rwrmGClWHNsHvRUXGNDN3 o3xZHKUjeRZzTbc8UCIfokazk2Lx2TlITbMcAegD711GQxuyCIeFXh3NTPbvKyRFRe 07rYHw/mSRUoWblECsj4w4ceGpVMhav5RY/8vweQ= 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-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+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1743787229936966313?= X-GMAIL-MSGID: =?utf-8?q?1743787229936966313?= 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(); +}