https://github.com/zyn0217 created 
https://github.com/llvm/llvm-project/pull/218577

It turns out that PackIndexingExpr doesn't create any PackExpansionTypes for 
unexpanded packs and thus we don't have to remove the packs during the 
normalization.

This also reverts the previous attempt f3fd5b2dd9 that doesn't completely solve 
the problem.

Fixes #218548


>From a4d8587ef8a41cff0dcfda65eadbd1f5214ab285 Mon Sep 17 00:00:00 2001
From: Younan Zhang <[email protected]>
Date: Tue, 25 Aug 2026 11:17:35 +0800
Subject: [PATCH] [Clang] Fix C++26 fold expression normalization of
 PackIndexingExpr

It turns out that PackIndexingExpr doesn't create any PackExpansionTypes
for unexpanded packs and thus we don't have to remove the packs
during the normalization.

This also reverts the previous attempt f3fd5b2dd9 that doesn't completely
solve the problem.
---
 clang/lib/Sema/SemaConcept.cpp          |  6 ++++++
 clang/lib/Sema/TreeTransform.h          |  4 ----
 clang/test/SemaCXX/cxx2c-fold-exprs.cpp | 18 ++++++++++++++++++
 3 files changed, 24 insertions(+), 4 deletions(-)

diff --git a/clang/lib/Sema/SemaConcept.cpp b/clang/lib/Sema/SemaConcept.cpp
index def80e274e10c..e6ef73b5a2d53 100644
--- a/clang/lib/Sema/SemaConcept.cpp
+++ b/clang/lib/Sema/SemaConcept.cpp
@@ -269,6 +269,12 @@ class AdjustConstraints : public 
TreeTransform<AdjustConstraints> {
     return Result;
   }
 
+  QualType TransformPackIndexingType(TypeLocBuilder &TLB,
+                                     PackIndexingTypeLoc TL) {
+    llvm::SaveAndRestore _1(RemoveNonPackExpansionPacks, false);
+    return inherited::TransformPackIndexingType(TLB, TL);
+  }
+
   bool AlreadyTransformed(QualType T) {
     if (T.isNull())
       return true;
diff --git a/clang/lib/Sema/TreeTransform.h b/clang/lib/Sema/TreeTransform.h
index b0c836325a971..4799f72dd6177 100644
--- a/clang/lib/Sema/TreeTransform.h
+++ b/clang/lib/Sema/TreeTransform.h
@@ -7124,10 +7124,6 @@ 
TreeTransform<Derived>::TransformPackIndexingType(TypeLocBuilder &TLB,
 
   for (QualType T : Types) {
     if (!T->containsUnexpandedParameterPack()) {
-      // A pack indexing type can appear in a larger pack expansion,
-      // e.g. `Pack...[pack_of_indexes]...`
-      // so we need to temporarily disable substitution of pack elements
-      Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), std::nullopt);
       QualType Transformed = getDerived().TransformType(T);
       if (Transformed.isNull())
         return QualType();
diff --git a/clang/test/SemaCXX/cxx2c-fold-exprs.cpp 
b/clang/test/SemaCXX/cxx2c-fold-exprs.cpp
index 79d57a6f94d58..b7b03278da54e 100644
--- a/clang/test/SemaCXX/cxx2c-fold-exprs.cpp
+++ b/clang/test/SemaCXX/cxx2c-fold-exprs.cpp
@@ -641,3 +641,21 @@ void f()
 void g() { f<long long, float>(); }
 
 }
+
+namespace GH218548 {
+
+template <class T>
+concept same_as_impl = sizeof(T) == 2;
+template <typename... P>
+void f() requires(same_as_impl<P...[sizeof(P)]> && ...) // #GH218548_f
+{}
+void g() {
+  f<char, short, short>();
+
+  f<char, int, short>();
+  // expected-error@-1 {{no matching function}}
+  // expected-note@#GH218548_f {{constraints not satisfied}}
+  // expected-note@#GH218548_f {{invalid index}}
+}
+
+}

_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to