From patchwork Tue Jul 26 00:06:23 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 175 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:6a10:b5d6:b0:2b9:3548:2db5 with SMTP id v22csp1952020pxt; Mon, 25 Jul 2022 17:07:13 -0700 (PDT) X-Google-Smtp-Source: AGRyM1uYrLtbPdFKnwUymmEVnBYPIHcsb6yXnKvgqm/BikFofRw+OTnmMcKShaUNUsdSn+/CgnwE X-Received: by 2002:a05:6402:1cae:b0:43b:a3d8:854a with SMTP id cz14-20020a0564021cae00b0043ba3d8854amr15520040edb.276.1658794033353; Mon, 25 Jul 2022 17:07:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658794033; cv=none; d=google.com; s=arc-20160816; b=cZKqcybN+MLDT3eOR0ICGkLVNuMYVvDR5FU3r6+TafpayNJxEzbaCpHjTdYDFDY2z2 QI25krcaORUHHmja/WH1Gzh8ZIR8+pLh11ZjQ0cBSBUQhKWQG5qhQPo4hsvljLLaeP4z Y3Aoy7v84YFO5XSkwjjaeEPZQm0xle75HZcMv8h/SOZcdx0uBxiGz5DlPJZiS/8qD9LM Cg88zDDAQX4wGeIvSD9heIztdkIpfv401SwRaJzF7tLja05QzWL6td4i8k3YxfZyI0Z6 pM/8EPm5HqxaJ76vSTD+5maMz2VzT0WpChzgzRInf1LZsGbqtnRHuOFebXKQbyjowDvy XL0Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to: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=Fm5/g3ZGWmEd5BSHTWrTnp1zglkvfEFQ6GOxIydLwE8=; b=H5G2dIOs8hUEFLCMMOXzmcsCa6F1DhUIgxyPtotKnLqoPD4Y17TlDN7a19j/kxgZKC T2ulDwT6/xaqQXWq7PZO0J+pWN0CjWTH0cI7xDFEf7E8QAmfaXhbFl8mgySwFpLTWkrh 2LR8LyMu+smJFdWxXlvw37eYuTttvalAg27cD6kk5jGGWoOWJtvWQdU2Z5fFP8s1JCHx QVrcjz3lx2pnZrUyxztfbKvq3TyMXcklT2HUZV3+7gzxASc5x2yifZE+Wc9vcgLF1t/7 3z62ktO2G2qre4NNfxMtFBLufug9x3E1beWRNDkWjH55S+rw+El4u745GhAj68sWPzvZ M0RQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=TKYO2ewS; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 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 (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id l1-20020aa7c3c1000000b0043a4b3bd453si13547058edr.504.2022.07.25.17.07.12 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Jul 2022 17:07:13 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=TKYO2ewS; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 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 0D98A3858430 for ; Tue, 26 Jul 2022 00:07:12 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0D98A3858430 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1658794032; bh=Fm5/g3ZGWmEd5BSHTWrTnp1zglkvfEFQ6GOxIydLwE8=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=TKYO2ewSKE3ffSZsq06Ji+3kkO1drHwPra76qBXywFg88bifvq6XtJMnFBEnENFSb 7/slQG2gnw+3Jw/afjnEElaxBM5l/nubbTZqj+kLHvofJqSD1esGieJ3yQZefN4CTu ATdp6pcSMASvnMUdUXncnry8M9pG1BdXU6M+abcA= 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.129.124]) by sourceware.org (Postfix) with ESMTPS id F3AEF3858CDA for ; Tue, 26 Jul 2022 00:06:28 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org F3AEF3858CDA Received: from mail-qv1-f72.google.com (mail-qv1-f72.google.com [209.85.219.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-593-cC2lgby6NO6e6jLBSVdWvQ-1; Mon, 25 Jul 2022 20:06:27 -0400 X-MC-Unique: cC2lgby6NO6e6jLBSVdWvQ-1 Received: by mail-qv1-f72.google.com with SMTP id l6-20020a0ce846000000b00473fbfc0e87so8472893qvo.19 for ; Mon, 25 Jul 2022 17:06:27 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=Fm5/g3ZGWmEd5BSHTWrTnp1zglkvfEFQ6GOxIydLwE8=; b=axWMnRxxOZcXGAdHrnVESw7mNAqVfAsSKXCqznB7clfRX5F4tmRIShZgwGvwAz1F29 s5WU07QyAELuqRiMbeEmmRfsdOF7OgGDnu55iNDrPRkMLO4m9zuZsqu4LDFo20NcYRdH VLsz1zBwM+KkBbkEUO1q0oR2JyJSgYYMaCJCSjS9vTQ+N/Oyc/JEO3FDzQqKUXRR2OV0 HI/Ni5ic9jw2lwTUPQSJdrWq/bYznadnT48el6gmz0xW5wMes4Ej7gWYiboqTGVWpbNH KwbRYZop0ykEUcMLM5SMW7fECWzOOftNRaqklUKETxWGENAgxmTt6qZJdR1yK+BgQBUj bTUw== X-Gm-Message-State: AJIora/y6qjHlNUUT610oCkaQ66kwiVdbgfhLOUDrEhpMWdW7D/8a49Y HmbCgVMQvYw+aFKgoSc8ZS7a1Ae8iYoYeaPXFc2mDqS4Ae/TYrc5uu4jO3anqsaS/b/L0jxuCYD HM2IWQgLMj51UJgsujD933ugIDaUIckHpIyzn5zlqyrDNoAflApwmmqf8um2cPx8Xdg== X-Received: by 2002:a05:6214:d0b:b0:474:e3c:f37e with SMTP id 11-20020a0562140d0b00b004740e3cf37emr12901420qvh.80.1658793986518; Mon, 25 Jul 2022 17:06:26 -0700 (PDT) X-Received: by 2002:a05:6214:d0b:b0:474:e3c:f37e with SMTP id 11-20020a0562140d0b00b004740e3cf37emr12901385qvh.80.1658793986101; Mon, 25 Jul 2022 17:06:26 -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 bn14-20020a05622a1dce00b0031ebb1f8918sm8113927qtb.76.2022.07.25.17.06.25 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Jul 2022 17:06:25 -0700 (PDT) To: gcc-patches@gcc.gnu.org Subject: [pushed] c++: aggregate prvalue as for range [PR106230] Date: Mon, 25 Jul 2022 20:06:23 -0400 Message-Id: <20220726000623.1183241-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.5 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 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 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?1739371612284011841?= X-GMAIL-MSGID: =?utf-8?q?1739371612284011841?= Since my PR94041 work on temporary lifetime in aggregate initialization, we end up calling build_vec_init to initialize the reference-extended temporary for the artificial __for_range variable. And build_vec_init uses finish_for_stmt to implement its loop. That function assumes that if __for_range is in current_binding_level, we're finishing a range-for, and we should fix up the variable as it goes out of scope. But when called from build_vec_init we aren't finishing a range-for, and do_poplevel doesn't remove the variable from scope because stmts_are_full_exprs_p is false. So let's check that here as well, and leave the DECL_NAME alone. Tested x86_64-pc-linux-gnu, applying to trunk. PR c++/106230 gcc/cp/ChangeLog: * semantics.cc (finish_for_stmt): Check stmts_are_full_exprs_p. gcc/testsuite/ChangeLog: * g++.dg/cpp0x/range-for38.C: New test. --- gcc/cp/semantics.cc | 5 +++++ gcc/testsuite/g++.dg/cpp0x/range-for38.C | 16 ++++++++++++++++ 2 files changed, 21 insertions(+) create mode 100644 gcc/testsuite/g++.dg/cpp0x/range-for38.C base-commit: 4c6567b4090d9363f90b5c68e238e7d0964b6e89 diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index 96037c21b85..16dea0593b0 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -1411,6 +1411,11 @@ finish_for_stmt (tree for_stmt) add_stmt (do_poplevel (scope)); + /* If we're being called from build_vec_init, don't mess with the names of + the variables for an enclosing range-for. */ + if (!stmts_are_full_exprs_p ()) + return; + for (int i = 0; i < 3; i++) if (range_for_decl[i]) DECL_NAME (range_for_decl[i]) diff --git a/gcc/testsuite/g++.dg/cpp0x/range-for38.C b/gcc/testsuite/g++.dg/cpp0x/range-for38.C new file mode 100644 index 00000000000..39845b937c1 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/range-for38.C @@ -0,0 +1,16 @@ +// PR c++/106230 +// { dg-do compile { target c++11 } } + +struct A { + A(); + operator int(); +}; +template struct array { + A elts[N]; + A *begin(); + A *end(); +}; +void fn() { + for (int i : array<4>{}) + ; +}