{"id":2220191,"url":"http://patchwork.ozlabs.org/api/patches/2220191/?format=json","web_url":"http://patchwork.ozlabs.org/project/gcc/patch/adNPtKeCGfTsY0wD@tucnak/","project":{"id":17,"url":"http://patchwork.ozlabs.org/api/projects/17/?format=json","name":"GNU Compiler Collection","link_name":"gcc","list_id":"gcc-patches.gcc.gnu.org","list_email":"gcc-patches@gcc.gnu.org","web_url":null,"scm_url":null,"webscm_url":null,"list_archive_url":"","list_archive_url_format":"","commit_url_format":""},"msgid":"<adNPtKeCGfTsY0wD@tucnak>","list_archive_url":null,"date":"2026-04-06T06:16:21","name":"c++, v2: Fix up handling of for-range-decls of expansion stmt [PR124488]","commit_ref":null,"pull_url":null,"state":"new","archived":false,"hash":"6e2966bcecfe01a00c53accf8115e9373e383f83","submitter":{"id":671,"url":"http://patchwork.ozlabs.org/api/people/671/?format=json","name":"Jakub Jelinek","email":"jakub@redhat.com"},"delegate":null,"mbox":"http://patchwork.ozlabs.org/project/gcc/patch/adNPtKeCGfTsY0wD@tucnak/mbox/","series":[{"id":498873,"url":"http://patchwork.ozlabs.org/api/series/498873/?format=json","web_url":"http://patchwork.ozlabs.org/project/gcc/list/?series=498873","date":"2026-04-06T06:16:21","name":"c++, v2: Fix up handling of for-range-decls of expansion stmt [PR124488]","version":1,"mbox":"http://patchwork.ozlabs.org/series/498873/mbox/"}],"comments":"http://patchwork.ozlabs.org/api/patches/2220191/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/2220191/checks/","tags":{},"related":[],"headers":{"Return-Path":"<gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org>","X-Original-To":["incoming@patchwork.ozlabs.org","gcc-patches@gcc.gnu.org"],"Delivered-To":["patchwork-incoming@legolas.ozlabs.org","gcc-patches@gcc.gnu.org"],"Authentication-Results":["legolas.ozlabs.org;\n\tdkim=pass (1024-bit key;\n unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256\n header.s=mimecast20190719 header.b=UseFLfZc;\n\tdkim-atps=neutral","legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org\n (client-ip=2620:52:6:3111::32; helo=vm01.sourceware.org;\n envelope-from=gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org;\n receiver=patchwork.ozlabs.org)","sourceware.org;\n\tdkim=pass (1024-bit key,\n unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256\n header.s=mimecast20190719 header.b=UseFLfZc","sourceware.org; dmarc=pass (p=quarantine dis=none)\n header.from=redhat.com","sourceware.org; spf=pass smtp.mailfrom=redhat.com","server2.sourceware.org;\n arc=none smtp.remote-ip=170.10.129.124"],"Received":["from vm01.sourceware.org (vm01.sourceware.org\n [IPv6:2620:52:6:3111::32])\n\t(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n\t key-exchange x25519 server-signature ECDSA (secp384r1) server-digest SHA384)\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4fqClw4XNBz1yFt\n\tfor <incoming@patchwork.ozlabs.org>; Tue, 07 Apr 2026 01:23:56 +1000 (AEST)","from vm01.sourceware.org (localhost [127.0.0.1])\n\tby sourceware.org (Postfix) with ESMTP id 9BA094BA2E3D\n\tfor <incoming@patchwork.ozlabs.org>; Mon,  6 Apr 2026 15:23:54 +0000 (GMT)","from us-smtp-delivery-124.mimecast.com\n (us-smtp-delivery-124.mimecast.com [170.10.129.124])\n by sourceware.org (Postfix) with ESMTP id 648F34BA2E27\n for <gcc-patches@gcc.gnu.org>; Mon,  6 Apr 2026 15:23:05 +0000 (GMT)","from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com\n (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by\n relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3,\n cipher=TLS_AES_256_GCM_SHA384) id us-mta-107-ItvH1ZmPP4C7Cg1nrV5tug-1; Mon,\n 06 Apr 2026 11:23:03 -0400","from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com\n (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4])\n (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest\n SHA256)\n (No client certificate requested)\n by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS\n id D0E451955D88\n for <gcc-patches@gcc.gnu.org>; Mon,  6 Apr 2026 15:22:55 +0000 (UTC)","from tucnak.zalov.cz (unknown [10.44.48.95])\n by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with\n ESMTPS\n id 5D100300019F; Mon,  6 Apr 2026 15:22:55 +0000 (UTC)","from tucnak.zalov.cz (localhost [127.0.0.1])\n by tucnak.zalov.cz (8.18.1/8.18.1) with ESMTPS id 636FMqku2732542\n (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT);\n Mon, 6 Apr 2026 17:22:52 +0200","(from jakub@localhost)\n by tucnak.zalov.cz (8.18.1/8.18.1/Submit) id 636FMqZN2732541;\n Mon, 6 Apr 2026 17:22:52 +0200"],"DKIM-Filter":["OpenDKIM Filter v2.11.0 sourceware.org 9BA094BA2E3D","OpenDKIM Filter v2.11.0 sourceware.org 648F34BA2E27"],"DMARC-Filter":"OpenDMARC Filter v1.4.2 sourceware.org 648F34BA2E27","ARC-Filter":"OpenARC Filter v1.0.0 sourceware.org 648F34BA2E27","ARC-Seal":"i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1775488985; cv=none;\n b=bhV7CC2SWO79wO6tR6aVBU1ZZaGmuAotRTDqaC0tliWKpaZVcKK8eO9Ld8Kv1tdgDe71pMrEgpTApP1vz7O12efmnf62R21REkLryIsgA8AGWnJwDVTIJUSfcjIzpoZnl16JzxZr4uiBH1C42Xp4jnB94q0JiM+Hq8W+FS+Ox/M=","ARC-Message-Signature":"i=1; a=rsa-sha256; d=sourceware.org; s=key;\n t=1775488985; c=relaxed/simple;\n bh=gwz7MX7of3i1TIyAG3VRat0q3kmKl5K61JZSPLO7+Gk=;\n h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version;\n b=VvLsKbs5cU5ETThfw81qJWfEJIo45x8NQyBV5oOK60PFtpffWabef1tKpXyHqYvrJ+Co2RX+o9ZI/x8DZJoDMcMyPiCGklJff5N6c4Vu4awisY7RUFnnBlURQPHKFEji2VSkVL1csvzILy1gIMYQZNGEwC1rGSFrQoZ9ISPMAfE=","ARC-Authentication-Results":"i=1; server2.sourceware.org","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;\n s=mimecast20190719; t=1775488985;\n h=from:from:reply-to:reply-to:subject:subject:date:date:\n message-id:message-id:to:to:cc:cc:mime-version:mime-version:\n content-type:content-type:resent-to:resent-from:resent-message-id:\n in-reply-to:in-reply-to:references:references;\n bh=jepOze5gvc9BIL4MkWqnU4QMUMRWwilOnTryK/Amm+4=;\n b=UseFLfZcbIsacrBqBFieYOcEV4ih+zuLVaiQwiNH+yfZWfEa1xTKfisIXZdgu68RI16sCh\n tf9soygm6GFf7PlwGi/zoqfwP2LrxXQ+sr6vJnCcTPf5EtbZAoP/Ry8hcX1zYRo1k/9laV\n K83wHgU5Z+DTo0QkajMqY5HTHrRxtO8=","X-MC-Unique":"ItvH1ZmPP4C7Cg1nrV5tug-1","X-Mimecast-MFC-AGG-ID":"ItvH1ZmPP4C7Cg1nrV5tug_1775488982","Resent-From":"Jakub Jelinek <jakub@redhat.com>","Resent-Date":"Mon, 6 Apr 2026 17:22:52 +0200","Resent-Message-ID":"<adPPzNRZUnsFWSOj@tucnak>","Resent-To":"Jason Merrill <jason@redhat.com>, gcc-patches@gcc.gnu.org","Date":"Mon, 6 Apr 2026 08:16:21 +0200","From":"Jakub Jelinek <jakub@redhat.com>","To":"Jason Merrill <jason@redhat.com>","Cc":"gcc-patches@gcc.gnu.org","Subject":"[PATCH] c++, v2: Fix up handling of for-range-decls of expansion\n stmt [PR124488]","Message-ID":"<adNPtKeCGfTsY0wD@tucnak>","References":"<ab2WW_On7Q3fJflw@tucnak>\n <fb51fd58-34c4-4858-9f03-c7ca06866e3b@redhat.com>","MIME-Version":"1.0","In-Reply-To":"<fb51fd58-34c4-4858-9f03-c7ca06866e3b@redhat.com>","X-Scanned-By":"MIMEDefang 3.4.1 on 10.30.177.4","X-Mimecast-Spam-Score":"0","X-Mimecast-MFC-PROC-ID":"dmjz69ES0y_RuAYmUkuZqDLJt3T0pC0RYB-uJIWe0jg_1775488982","X-Mimecast-Originator":"redhat.com","Content-Type":"text/plain; charset=us-ascii","Content-Disposition":"inline","X-BeenThere":"gcc-patches@gcc.gnu.org","X-Mailman-Version":"2.1.30","Precedence":"list","List-Id":"Gcc-patches mailing list <gcc-patches.gcc.gnu.org>","List-Unsubscribe":"<https://gcc.gnu.org/mailman/options/gcc-patches>,\n <mailto:gcc-patches-request@gcc.gnu.org?subject=unsubscribe>","List-Archive":"<https://gcc.gnu.org/pipermail/gcc-patches/>","List-Post":"<mailto:gcc-patches@gcc.gnu.org>","List-Help":"<mailto:gcc-patches-request@gcc.gnu.org?subject=help>","List-Subscribe":"<https://gcc.gnu.org/mailman/listinfo/gcc-patches>,\n <mailto:gcc-patches-request@gcc.gnu.org?subject=subscribe>","Reply-To":"Jakub Jelinek <jakub@redhat.com>","Errors-To":"gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org"},"content":"On Fri, Apr 03, 2026 at 06:03:22PM -0400, Jason Merrill wrote:\n> > +  if (VAR_P (range_decl))\n> > +    {\n> > +      DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (range_decl) = 1;\n> > +      if (decl_maybe_constant_var_p (range_decl)\n> > +\t  /* FIXME setting TREE_CONSTANT on refs breaks the back end.  */\n> > +\t  && !TYPE_REF_P (TREE_TYPE (range_decl)))\n> > +\tTREE_CONSTANT (range_decl) = true;\n> > +      /* Make it value dependent.  */\n> > +      retrofit_lang_decl (range_decl);\n> > +      SET_DECL_DEPENDENT_INIT_P (range_decl, 1);\n> > +      DECL_INITIAL (range_decl) = for_range_identifier;\n> \n> Why is the dummy DECL_INITIAL needed as well as DECL_DEPENDENT_INIT_P?\n\nI was just afraid something might have called value_dependent_expression_p\nalso on the DECL_INITIAL and for NULL_TREE it returns false.\n\nBut I have nothing in the testsuite that would need it, so here is an\nupdated patch without that.\n\nBootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?\n\n2026-04-06  Jakub Jelinek  <jakub@redhat.com>\n\n\tPR c++/124488\n\t* parser.cc (cp_parser_expansion_statement): Set\n\tDECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P, DECL_DEPENDENT_INIT_P and\n\tif maybe constant non-reference TREE_CONSTANT on range_decl.\n\t* pt.cc (tsubst_stmt) <case TEMPLATE_FOR_STMT>: Set\n\tDECL_DEPENDENT_INIT_P on decl.\n\n\t* g++.dg/cpp26/expansion-stmt33.C: New test.\n\n\n\n\tJakub","diff":"--- gcc/cp/parser.cc.jj\t2026-03-18 06:35:08.369968785 +0100\n+++ gcc/cp/parser.cc\t2026-03-20 10:24:40.519275212 +0100\n@@ -16677,6 +16677,20 @@ cp_parser_expansion_statement (cp_parser\n   TEMPLATE_FOR_EXPR (r) = expansion_init;\n   TEMPLATE_FOR_BODY (r) = do_pushlevel (sk_block);\n \n+  /* We don't know yet if range_decl will be initialized by constant\n+     expression or not.  */\n+  if (VAR_P (range_decl))\n+    {\n+      DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (range_decl) = 1;\n+      if (decl_maybe_constant_var_p (range_decl)\n+\t  /* FIXME setting TREE_CONSTANT on refs breaks the back end.  */\n+\t  && !TYPE_REF_P (TREE_TYPE (range_decl)))\n+\tTREE_CONSTANT (range_decl) = true;\n+      /* Make it value dependent.  */\n+      retrofit_lang_decl (range_decl);\n+      SET_DECL_DEPENDENT_INIT_P (range_decl, 1);\n+    }\n+\n   /* Parse the body of the expansion-statement.  */\n   parser->in_statement = IN_EXPANSION_STMT;\n   bool prev = note_iteration_stmt_body_start ();\n--- gcc/cp/pt.cc.jj\t2026-03-18 06:35:08.372968734 +0100\n+++ gcc/cp/pt.cc\t2026-03-20 10:24:49.890114568 +0100\n@@ -19776,6 +19776,11 @@ tsubst_stmt (tree t, tree args, tsubst_flags_t complain, tree in_decl)\n \t      orig_decl = TREE_VEC_ELT (orig_decl, 0);\n \t    tree decl = tsubst (orig_decl, args, complain, in_decl);\n \t    maybe_push_decl (decl);\n+\t    if (VAR_P (decl))\n+\t      {\n+\t\tretrofit_lang_decl (decl);\n+\t\tSET_DECL_DEPENDENT_INIT_P (decl, 1);\n+\t      }\n \n \t    cp_decomp decomp_d, *decomp = NULL;\n \t    if (DECL_DECOMPOSITION_P (decl))\n--- gcc/testsuite/g++.dg/cpp26/expansion-stmt33.C.jj\t2026-03-20 10:02:54.569810934 +0100\n+++ gcc/testsuite/g++.dg/cpp26/expansion-stmt33.C\t2026-03-20 10:27:18.603565158 +0100\n@@ -0,0 +1,17 @@\n+// PR c++/124488\n+// { dg-do compile { target c++11 } }\n+// { dg-options \"\" }\n+\n+void\n+foo ()\n+{\n+  template for (constexpr int a : { 42 })\t// { dg-warning \"'template for' only available with\" \"\" { target c++23_down } }\n+    auto b = [] () { return a; };\n+}\n+\n+void\n+bar (int x)\n+{\n+  template for (const int a : { 42, ++x, 5 })\t// { dg-warning \"'template for' only available with\" \"\" { target c++23_down } }\n+    const int b = a;\n+}\n","prefixes":[]}