[clang] [clang][constexpr] Fix assertion failure in C++26 constexpr structured binding pack evaluation (#170991) (PR #213534)

via cfe-commits cfe-commits at lists.llvm.org
Fri Aug 7 07:36:46 PDT 2026


================
@@ -155,3 +155,128 @@ constexpr auto [e1] = E(true);
 //   expected-note at -1 {{in implicit initialization of binding declaration 'e1'}} \
 //   expected-note at -1 {{reference to temporary is not a constant expression}} \
 //   expected-note@#E-get {{temporary created here}}
+
+namespace GH170991 {
+// Test case: struct
+struct S { int x{}; };
+
+template <typename = void>
+void f() {
+  constexpr S s;
+  constexpr auto [x] = s;
+  constexpr auto [...xs] = s;
+}
+
+template void f<void>();
+
+// Test case: array
+template <typename = void>
+void g() {
+  constexpr int a[2]{};
+  constexpr auto [x, y] = a;
+  constexpr auto [...xs] = a;
+}
+
+template void g<void>();
+} // namespace GH170991
+
+// Test case: tuple-like
+namespace GH170991 {
+struct TupleLikeFnTemplate {
+  int x = 100;
+  char y = 'D';
+
+  // If a search for the name get in the scope of E [...] the initializer is e.get<i>()
+  template <unsigned I>
+  constexpr decltype(auto) get() const& {
----------------
babadany2999 wrote:

Reference is unnecessary.

https://github.com/llvm/llvm-project/pull/213534


More information about the cfe-commits mailing list