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: 56322 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id B9A07383B786 for ; Tue, 26 Jul 2022 00:06:57 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B9A07383B786 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1658794017; bh=Fm5/g3ZGWmEd5BSHTWrTnp1zglkvfEFQ6GOxIydLwE8=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=GFrSN6d+7TWCrDI67UW3l0/NQw9c8ayHuyHByefLDRKWaR//pvaETsWEGdD23gNzp KtUcMfhvLpPGwEZkHaZkjpnfZhET+idlRqDyH+FbqaA+FHhXr5bxM4EHrtsnxhuvhi 0RGQB5aNGBHjQuELaHtPewcolYx1ZDQXhqAYpuwU= 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-Google-Smtp-Source: AGRyM1sQmwqEzR0U5+wShQRRGUTyS/cPcC3G5GJ/oG/diB///XYfqaaQyeO5FDzj34vG32YlnxOCwQ== 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+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" 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>{}) + ; +}