{"id":2225512,"url":"http://patchwork.ozlabs.org/api/patches/2225512/?format=json","web_url":"http://patchwork.ozlabs.org/project/gcc/patch/aecTzk_qu3pwvpEf@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":"<aecTzk_qu3pwvpEf@tucnak>","list_archive_url":null,"date":"2026-04-21T06:06:06","name":"c++: Fix up iterating expansion stmt b and e var handling [PR124927]","commit_ref":null,"pull_url":null,"state":"new","archived":false,"hash":"ec8557dd5447abdc0d7ed9154913a56fd115597b","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/aecTzk_qu3pwvpEf@tucnak/mbox/","series":[{"id":500737,"url":"http://patchwork.ozlabs.org/api/series/500737/?format=json","web_url":"http://patchwork.ozlabs.org/project/gcc/list/?series=500737","date":"2026-04-21T06:06:06","name":"c++: Fix up iterating expansion stmt b and e var handling [PR124927]","version":1,"mbox":"http://patchwork.ozlabs.org/series/500737/mbox/"}],"comments":"http://patchwork.ozlabs.org/api/patches/2225512/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/2225512/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=hCyRoRzo;\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=hCyRoRzo","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 4g0Bh137p9z1yGt\n\tfor <incoming@patchwork.ozlabs.org>; Tue, 21 Apr 2026 16:06:41 +1000 (AEST)","from vm01.sourceware.org (localhost [127.0.0.1])\n\tby sourceware.org (Postfix) with ESMTP id 8750A4BA900D\n\tfor <incoming@patchwork.ozlabs.org>; Tue, 21 Apr 2026 06:06:39 +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 4620B4BA2E30\n for <gcc-patches@gcc.gnu.org>; Tue, 21 Apr 2026 06:06:13 +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-361-tF2KC3DiN0GuuUsAWbsDCw-1; Tue,\n 21 Apr 2026 02:06:11 -0400","from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com\n (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17])\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 64E5519560BB\n for <gcc-patches@gcc.gnu.org>; Tue, 21 Apr 2026 06:06:10 +0000 (UTC)","from tucnak.zalov.cz (unknown [10.44.48.12])\n by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with\n ESMTPS\n id BC879195608E; Tue, 21 Apr 2026 06:06:09 +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 63L667C4886149\n (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT);\n Tue, 21 Apr 2026 08:06:07 +0200","(from jakub@localhost)\n by tucnak.zalov.cz (8.18.1/8.18.1/Submit) id 63L666sP886148;\n Tue, 21 Apr 2026 08:06:06 +0200"],"DKIM-Filter":["OpenDKIM Filter v2.11.0 sourceware.org 8750A4BA900D","OpenDKIM Filter v2.11.0 sourceware.org 4620B4BA2E30"],"DMARC-Filter":"OpenDMARC Filter v1.4.2 sourceware.org 4620B4BA2E30","ARC-Filter":"OpenARC Filter v1.0.0 sourceware.org 4620B4BA2E30","ARC-Seal":"i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1776751573; cv=none;\n b=jTIg7Ktj5yQnsbdioj/qs8ZuyxLpR/S1B8Lb0yh121Zzzkb2uJSIi26HetbqJezbxSLHKsicQ/RjEi+ERjoBpaiQ3BT98sktl5D9nh85ERwabeGy+Il3n2eM5ST2lWAnRszTrjNiqj7V85FDq9UVanwJPGV5pRGbg+JD2LLsz1k=","ARC-Message-Signature":"i=1; a=rsa-sha256; d=sourceware.org; s=key;\n t=1776751573; c=relaxed/simple;\n bh=7ihh6aDZnXzMXbmt2qszTFWlB80P5XP6zDPbDyTACZM=;\n h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version;\n b=ezbUnzpgQZp37asJjRp2DZLZV/1NU8VDIfCErGsyC6THmT6iG3QquEWKRaggzk2mQPeHpPEyWcP5W05c8kzas/ZEoFmcgkY+FuSRURyERKCMWNHN8wMgzIwpO+1XDZtbqmgOe3kYSf5o1dlAd2I4iOTeyxXeU++5MhG8rtZzWto=","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=1776751573;\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; bh=fu/KhM2FzkC/aA0p6q/FBeoAd8gn/1gOStpfDQhL+fQ=;\n b=hCyRoRzosDVeA3WyM++EyvwChqTXXj9QoueF2bIblQtMOP9MCEozYnA8QVp0cgcWLh5Aiu\n t2RGEFQDVKfg0PiCdYx4fSDBPcyCDjnMnMwEI0UHLYubWObkJS6wggzV2E6GIv248n6z4/\n pFGdM0+wylktVlON1QC1imBZzuEtBO4=","X-MC-Unique":"tF2KC3DiN0GuuUsAWbsDCw-1","X-Mimecast-MFC-AGG-ID":"tF2KC3DiN0GuuUsAWbsDCw_1776751570","Date":"Tue, 21 Apr 2026 08:06:06 +0200","From":"Jakub Jelinek <jakub@redhat.com>","To":"Jason Merrill <jason@redhat.com>","Cc":"gcc-patches@gcc.gnu.org","Subject":"[PATCH] c++: Fix up iterating expansion stmt b and e var handling\n [PR124927]","Message-ID":"<aecTzk_qu3pwvpEf@tucnak>","MIME-Version":"1.0","X-Scanned-By":"MIMEDefang 3.0 on 10.30.177.17","X-Mimecast-Spam-Score":"0","X-Mimecast-MFC-PROC-ID":"IvfP3YLFLt_08r9Ks-hQVafKpkD5642opbNon-XuCt4_1776751570","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":"Hi!\n\nThe following testcase ICEs, because the TARGET_EXPR it had has VOID_TYPE\nTARGET_EXPR_INITIAL and force_target_expr obviously ICEs when trying to\ncreate a VOID_TYPE TARGET_EXPR.\n\nThis patch fixes it by taking the cv_unqualified type of the TARGET_EXPRs\nbefore we extract their TARGET_EXPR_INITIAL, so it does the desirable thing\nof recreating the TARGET_EXPRs with cv unqualified types.\n\nBootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?\n\n2026-04-21  Jakub Jelinek  <jakub@redhat.com>\n\n\tPR c++/124927\n\t* pt.cc (finish_expansion_stmt): Compute types for force_target_expr\n\tfrom b and e before extracting TARGET_EXPR_INITIAL from it.\n\n\t* g++.dg/cpp26/expansion-stmt41.C: New test.\n\n\n\tJakub","diff":"--- gcc/cp/pt.cc.jj\t2026-04-16 18:56:51.668066801 +0200\n+++ gcc/cp/pt.cc\t2026-04-20 13:30:31.137795700 +0200\n@@ -33499,14 +33499,14 @@ finish_expansion_stmt (tree expansion_st\n \t     so that e.g. b can be incremented, so unwrap the TARGET_EXPRs\n \t     and force TARGET_EXPR with the cv-unqualified type which is\n \t     a hack replacement for a VAR_DECL in a lambda.  */\n+\t  tree btype = cv_unqualified (TREE_TYPE (b));\n+\t  tree etype = cv_unqualified (TREE_TYPE (e));\n \t  if (TREE_CODE (b) == TARGET_EXPR)\n \t    b = TARGET_EXPR_INITIAL (b);\n \t  if (TREE_CODE (e) == TARGET_EXPR)\n \t    e = TARGET_EXPR_INITIAL (e);\n-\t  b = force_target_expr (cv_unqualified (TREE_TYPE (b)), b,\n-\t\t\t\t tf_warning_or_error);\n-\t  e = force_target_expr (cv_unqualified (TREE_TYPE (e)), e,\n-\t\t\t\t tf_warning_or_error);\n+\t  b = force_target_expr (btype, b, tf_warning_or_error);\n+\t  e = force_target_expr (etype, e, tf_warning_or_error);\n \t  tree w = build_stmt (loc, WHILE_STMT, NULL_TREE, NULL_TREE,\n \t\t\t       NULL_TREE, NULL_TREE, NULL_TREE);\n \t  tree r = get_target_expr (build_zero_cst (ptrdiff_type_node));\n--- gcc/testsuite/g++.dg/cpp26/expansion-stmt41.C.jj\t2026-04-20 13:49:08.090898732 +0200\n+++ gcc/testsuite/g++.dg/cpp26/expansion-stmt41.C\t2026-04-20 13:54:28.439482931 +0200\n@@ -0,0 +1,28 @@\n+// PR c++/124927\n+// { dg-do run { target c++23 } }\n+// { dg-options \"\" }\n+\n+#include <array>\n+#include <ranges>\n+\n+constexpr std::array a { 1, 2, 3, 4, 5 };\n+constexpr std::array b { 5, 4, 3, 2, 1 };\n+\n+int\n+foo (int i)\n+{\n+  template for (constexpr auto z : std::views::zip (a, b)) // { dg-warning \"'template for' only available with\" \"\" { target c++23_down } }\n+    if (i == get <0> (z))\n+      return get <1> (z);\n+  return 0;\n+}\n+\n+int\n+main ()\n+{\n+  for (int i = 1; i <= 5; ++i)\n+    if (foo (i) != 6 - i)\n+      __builtin_abort ();\n+  if (foo (0) != 0 || foo (6) != 0)\n+    __builtin_abort ();\n+}\n","prefixes":[]}