{"id":2219522,"url":"http://patchwork.ozlabs.org/api/patches/2219522/?format=json","web_url":"http://patchwork.ozlabs.org/project/gcc/patch/ac9_k-LZ0JWy7Dwc@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":"<ac9_k-LZ0JWy7Dwc@tucnak>","list_archive_url":null,"date":"2026-04-03T08:51:31","name":"c++: Implement CWG3135 - constexpr structured bindings with prvalues from tuples","commit_ref":null,"pull_url":null,"state":"new","archived":false,"hash":"26096aa0f8b1fcb2c6753b462845f8dbc6e7e19d","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/ac9_k-LZ0JWy7Dwc@tucnak/mbox/","series":[{"id":498605,"url":"http://patchwork.ozlabs.org/api/series/498605/?format=json","web_url":"http://patchwork.ozlabs.org/project/gcc/list/?series=498605","date":"2026-04-03T08:51:31","name":"c++: Implement CWG3135 - constexpr structured bindings with prvalues from tuples","version":1,"mbox":"http://patchwork.ozlabs.org/series/498605/mbox/"}],"comments":"http://patchwork.ozlabs.org/api/patches/2219522/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/2219522/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=Y4K6j+p7;\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=Y4K6j+p7","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 4fnCCG2SF8z1yCs\n\tfor <incoming@patchwork.ozlabs.org>; Fri, 03 Apr 2026 19:52:08 +1100 (AEDT)","from vm01.sourceware.org (localhost [127.0.0.1])\n\tby sourceware.org (Postfix) with ESMTP id AB6C64BA2E06\n\tfor <incoming@patchwork.ozlabs.org>; Fri,  3 Apr 2026 08:52:06 +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 DCBCE4BA23D3\n for <gcc-patches@gcc.gnu.org>; Fri,  3 Apr 2026 08:51:37 +0000 (GMT)","from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com\n (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by\n relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3,\n cipher=TLS_AES_256_GCM_SHA384) id us-mta-139-Qq5wBdWGPbKVeMH-Lgm-xQ-1; Fri,\n 03 Apr 2026 04:51:36 -0400","from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com\n (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111])\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-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS\n id 208E71800359\n for <gcc-patches@gcc.gnu.org>; Fri,  3 Apr 2026 08:51:35 +0000 (UTC)","from tucnak.zalov.cz (unknown [10.44.32.9])\n by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with\n ESMTPS\n id A861E180035F; Fri,  3 Apr 2026 08:51:34 +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 6338pVBi3680583\n (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT);\n Fri, 3 Apr 2026 10:51:31 +0200","(from jakub@localhost)\n by tucnak.zalov.cz (8.18.1/8.18.1/Submit) id 6338pVAA3680582;\n Fri, 3 Apr 2026 10:51:31 +0200"],"DKIM-Filter":["OpenDKIM Filter v2.11.0 sourceware.org AB6C64BA2E06","OpenDKIM Filter v2.11.0 sourceware.org DCBCE4BA23D3"],"DMARC-Filter":"OpenDMARC Filter v1.4.2 sourceware.org DCBCE4BA23D3","ARC-Filter":"OpenARC Filter v1.0.0 sourceware.org DCBCE4BA23D3","ARC-Seal":"i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1775206298; cv=none;\n b=S98jJUIF9y/Hk7fA+ZJIfNXVT+ZnDBTafx2wo6HhVQ4KFzX0sSzZ62MENGZTEY1aj5CMquCNWMPJRc2o5R8bJhlJ8orfmIQQONnr2csBJojaZQ6com0QLzqXfUI1Fk3neY1MZlbxqU5ygaBbt005N4DoGJNjhnrvEvzmypq8vcE=","ARC-Message-Signature":"i=1; a=rsa-sha256; d=sourceware.org; s=key;\n t=1775206298; c=relaxed/simple;\n bh=/eL6zvmJ3AbQ/Hm3s5zxtgIGG/y6tSeFfFS7t+x9LF4=;\n h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version;\n b=M1IkUZzbiLVlm6DOBcbQVzhmRarsdk8o8ubQkmVTDuuh5mo9pMF7qDTveLN0VKUZNU4WCsL6S+dvBve5r/f9SOza+cs/kSfggsaYLAt9brn5n8F2VJJvbcBVaTVgPnAoPAg9xfNX2dKGknjDp4AlBZczVRwFos2K9srmIi/W75s=","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=1775206297;\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=Ho7r0h63uWW+99Ht45MYMpE777vSt7oXfIbV5Llp9Z0=;\n b=Y4K6j+p7VfDRhwAupofQbo6Kw0OZpFcmU83ypxqWcTCGM919uzw6irjj8KpHAA56e9VYbm\n olNvHKBQljWbrbb0Fn476RsF3a1C2D7MssaQIINh8vvMpfMVpOhpwpxoxBZH+Vq5LTP3cj\n /qA9XO4QhD3Y8ZI7G6fQw7IPwUkA2J8=","X-MC-Unique":"Qq5wBdWGPbKVeMH-Lgm-xQ-1","X-Mimecast-MFC-AGG-ID":"Qq5wBdWGPbKVeMH-Lgm-xQ_1775206295","Date":"Fri, 3 Apr 2026 10:51:31 +0200","From":"Jakub Jelinek <jakub@redhat.com>","To":"Jason Merrill <jason@redhat.com>","Cc":"gcc-patches@gcc.gnu.org","Subject":"[PATCH] c++: Implement CWG3135 - constexpr structured bindings with\n prvalues from tuples","Message-ID":"<ac9_k-LZ0JWy7Dwc@tucnak>","MIME-Version":"1.0","X-Scanned-By":"MIMEDefang 3.4.1 on 10.30.177.111","X-Mimecast-Spam-Score":"0","X-Mimecast-MFC-PROC-ID":"FmF8SawnaylKzPpkzTG-CNNE4NFhV9tbVVbE0KvuTvA_1775206295","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 patch implements another CWG issue, added e.g. for the\nP1789R3 (Library Support for Expansion Statements) APIs where get returns\na prvalue rather than a reference.\n\nThe gomp testcase was using get returning prvalue and the changes\ncause some changes in lines on which stuff is reported.\n\nBootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?\n\n2026-04-03  Jakub Jelinek  <jakub@redhat.com>\n\n\t* decl.cc (cp_finish_decomp): Implement CWG3135 - constexpr structured\n\tbindings with prvalues from tuples.  Don't call cp_build_reference_type\n\tif init is prvalue for C++26.\n\n\t* g++.dg/cpp26/decomp30.C: New test.\n\t* g++.dg/gomp/pr108503.C: Expect diagnostics in C++26 on a different\n\tline.\n\n\n\tJakub","diff":"--- gcc/cp/decl.cc.jj\t2026-04-01 20:10:43.899063964 +0200\n+++ gcc/cp/decl.cc\t2026-04-02 16:26:49.865791353 +0200\n@@ -11011,7 +11011,8 @@ cp_finish_decomp (tree decl, cp_decomp *\n \t\t  maybe_push_decl (t);\n \t\t  /* Save the decltype away before reference collapse.  */\n \t\t  hash_map_safe_put<hm_ggc> (decomp_type_table, t, eltype);\n-\t\t  eltype = cp_build_reference_type (eltype, !lvalue_p (init));\n+\t\t  if (cxx_dialect < cxx26 || glvalue_p (init))\n+\t\t    eltype = cp_build_reference_type (eltype, !lvalue_p (init));\n \t\t  TREE_TYPE (t) = eltype;\n \t\t  layout_decl (t, 0);\n \t\t  DECL_HAS_VALUE_EXPR_P (t) = 0;\n@@ -11056,7 +11057,8 @@ cp_finish_decomp (tree decl, cp_decomp *\n \t    }\n \t  /* Save the decltype away before reference collapse.  */\n \t  hash_map_safe_put<hm_ggc> (decomp_type_table, v[i], eltype);\n-\t  eltype = cp_build_reference_type (eltype, !lvalue_p (init));\n+\t  if (cxx_dialect < cxx26 || glvalue_p (init))\n+\t    eltype = cp_build_reference_type (eltype, !lvalue_p (init));\n \t  TREE_TYPE (v[i]) = eltype;\n \t  layout_decl (v[i], 0);\n \t  if (DECL_HAS_VALUE_EXPR_P (v[i]))\n--- gcc/testsuite/g++.dg/cpp26/decomp30.C.jj\t2026-04-02 16:55:02.549367082 +0200\n+++ gcc/testsuite/g++.dg/cpp26/decomp30.C\t2026-04-02 16:54:45.142659067 +0200\n@@ -0,0 +1,37 @@\n+// CWG3135 - constexpr structured bindings with prvalues from tuples\n+// { dg-do compile { target c++11 } }\n+// { dg-options \"\" }\n+\n+namespace std {\n+  template <typename T> struct tuple_size;\n+  template <int, typename> struct tuple_element;\n+}\n+\n+struct A {\n+  template <int I> constexpr int get () const { return I + 6; }\n+};\n+\n+template <> struct std::tuple_size <A> { static const int value = 2; };\n+template <int I> struct std::tuple_element <I, A> { using type = int; };\n+template <> struct std::tuple_size <const A> { static const int value = 2; };\n+template <int I> struct std::tuple_element <I, const A> { using type = const int; };\n+\n+constexpr A\n+bar ()\n+{\n+  return A {};\n+}\n+\n+template <int N>\n+constexpr int\n+foo ()\n+{\n+  constexpr auto [...i] = bar ();\t// { dg-warning \"structured binding packs only available with\" \"\" { target { c++17 && c++23_down } } }\n+\t\t\t\t\t// { dg-warning \"structured binding declaration can be 'constexpr' only with\" \"\" { target c++23_down } .-1 }\n+\t\t\t\t\t// { dg-warning \"structured bindings only available with\" \"\" { target c++14_down } .-2 }\n+\t\t\t\t\t// { dg-error \"'<anonymous>' is not a constant expression\" \"\" { target c++23_down } .-3 }\n+  return i...[0] + i...[1];\t\t// { dg-warning \"pack indexing only available with\" \"\" { target c++23_down } }\n+}\n+\n+static_assert (foo <42> () == 13);\t// { dg-error \"non-constant condition for static assertion\" \"\" { target c++23_down } }\n+\t\t\t\t\t// { dg-error \"called in a constant expression\" \"\" { target c++23_down } .-1 }\n--- gcc/testsuite/g++.dg/gomp/pr108503.C.jj\t2023-01-26 14:11:48.505599103 +0100\n+++ gcc/testsuite/g++.dg/gomp/pr108503.C\t2026-04-03 10:33:02.591824046 +0200\n@@ -20,8 +20,8 @@ struct B {\n void\n foo (B a)\n {\n-  #pragma omp for collapse(2)\n-  for (auto [i, j, k] : a)\n-    for (int l = i; l < j; l += k)\t// { dg-error \"initializer expression refers to iteration variable 'i'\" }\n+  #pragma omp for collapse(2)\t\t// { dg-error \"increment expression refers to iteration variable 'k'\" \"\" { target c++26 } .+1 }\n+  for (auto [i, j, k] : a)\t\t// { dg-error \"initializer expression refers to iteration variable 'i'\" \"\" { target c++26 } }\n+    for (int l = i; l < j; l += k)\t// { dg-error \"initializer expression refers to iteration variable 'i'\" \"\" { target c++23_down } }\n       ;\t\t\t\t\t// { dg-error \"condition expression refers to iteration variable 'j'\" \"\" { target *-*-* } .-1 }\n-}\t\t\t\t\t// { dg-error \"increment expression refers to iteration variable 'k'\" \"\" { target *-*-* } .-2 }\n+}\t\t\t\t\t// { dg-error \"increment expression refers to iteration variable 'k'\" \"\" { target c++23_down } .-2 }\n","prefixes":[]}