[clang] [clang] propagate constexpr to binding VarDecl (PR #195860)

Matthias Wippich via cfe-commits cfe-commits at lists.llvm.org
Tue May 5 07:08:16 PDT 2026


https://github.com/Tsche created https://github.com/llvm/llvm-project/pull/195860

This patch implements one of the missing parts of P2686. This is required to make the test case from [cwg3135](https://cplusplus.github.io/CWG/issues/3135.html) (and likewise the examples of [P1789](https://wg21.link/p1789) work).


>From 655008393b21af71b76e0c0e3a9b256b663c0129 Mon Sep 17 00:00:00 2001
From: Matthias Wippich <mfwippich at gmail.com>
Date: Mon, 4 May 2026 05:30:53 +0200
Subject: [PATCH] [clang] propagate constexpr to binding VarDecl

---
 clang/lib/Sema/SemaDeclCXX.cpp             | 1 +
 clang/test/SemaCXX/cxx2c-decomposition.cpp | 4 ----
 2 files changed, 1 insertion(+), 4 deletions(-)

diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index 1e339fee29ab8..d8b7b20e6dbee 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -1401,6 +1401,7 @@ static bool checkTupleLikeDecomposition(Sema &S,
                         /*TInfo=*/nullptr, Src->getStorageClass());
     RefVD->setLexicalDeclContext(Src->getLexicalDeclContext());
     RefVD->setTSCSpec(Src->getTSCSpec());
+    RefVD->setConstexpr(Src->isConstexpr());
     RefVD->setImplicit();
     if (Src->isInlineSpecified())
       RefVD->setInlineSpecified();
diff --git a/clang/test/SemaCXX/cxx2c-decomposition.cpp b/clang/test/SemaCXX/cxx2c-decomposition.cpp
index 99278c6575ef1..3e7fdfc904958 100644
--- a/clang/test/SemaCXX/cxx2c-decomposition.cpp
+++ b/clang/test/SemaCXX/cxx2c-decomposition.cpp
@@ -62,12 +62,8 @@ void test() {
     test_tpl(0);
 }
 
-// FIXME : support tuple
 constexpr auto [a, b] = B{};
 static_assert(a.n == 0);
-// expected-error at -1 {{static assertion expression is not an integral constant expression}} \
-// expected-note at -1 {{read of temporary is not allowed in a constant expression outside the expression that created the temporary}}\
-// expected-note at -2 {{temporary created here}}
 
 constinit auto [init1] = Y {42};
 constinit auto [init2] = X {};  // expected-error {{variable does not have a constant initializer}} \



More information about the cfe-commits mailing list