[clang] [clang] Fix assertion failure on direct initialization of an alias with an unexpanded pack from a parenthesized braced-init-list (PR #236838)
Harlen Batagelo via cfe-commits
cfe-commits at lists.llvm.org
Thu Oct 29 09:51:46 PDT 2026
https://github.com/hbatagelo created https://github.com/llvm/llvm-project/pull/236838
Fixes #113762.
Given
```cpp
template<typename T> using Int = int;
template<typename ...Ts> void Pack() {
Int<Ts>({});
}
```
Sema wraps the ill-formed `Int<Ts>({})` in a `RecoveryExpr` whose type is the sugared `Int<Ts>`, so `containsUnexpandedParameterPack()` is `true`. But the collector invoked by `Sema::DiagnoseUnexpandedParameterPack` only walks the subexpression (`InitListExpr`) which doesn't mention the pack. The traversal finds nothing, triggering the assertion https://github.com/llvm/llvm-project/blob/3bf0a2073bd4ef0a744601305d62ab058233a9ed/clang/lib/Sema/SemaTemplateVariadic.cpp#L566-L567
Fix by overriding `TraverseRecoveryExpr` in `CollectUnexpandedParameterPacksVisitor` to also traverse the `RecoveryExpr`'s type.
>From e782852154065ff4102fe08c57f864d87c4f8a52 Mon Sep 17 00:00:00 2001
From: Harlen Batagelo <hbatagelo at gmail.com>
Date: Thu, 29 Oct 2026 12:41:11 -0300
Subject: [PATCH 1/2] Override TraverseRecoveryExpr
---
clang/lib/Sema/SemaTemplateVariadic.cpp | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/clang/lib/Sema/SemaTemplateVariadic.cpp b/clang/lib/Sema/SemaTemplateVariadic.cpp
index 2d6e75bd77b402..bda26f5d6aeca6 100644
--- a/clang/lib/Sema/SemaTemplateVariadic.cpp
+++ b/clang/lib/Sema/SemaTemplateVariadic.cpp
@@ -384,6 +384,13 @@ class CollectUnexpandedParameterPacksVisitor
return DynamicRecursiveASTVisitor::TraverseUnresolvedLookupExpr(E);
}
+ bool TraverseRecoveryExpr(RecoveryExpr *E) override {
+ if (!DynamicRecursiveASTVisitor::TraverseRecoveryExpr(E))
+ return false;
+ TraverseType(E->getType());
+ return true;
+ }
+
bool TraverseSubstBuiltinTemplatePackType(SubstBuiltinTemplatePackType *T,
bool TraverseQualifier) override {
addUnexpanded(T);
>From f77dea117a235cc29f31824d047d5ff307a10218 Mon Sep 17 00:00:00 2001
From: Harlen Batagelo <hbatagelo at gmail.com>
Date: Thu, 29 Oct 2026 13:47:46 -0300
Subject: [PATCH 2/2] Add test
---
clang/test/SemaTemplate/find-unexpanded-packs.cpp | 1 +
1 file changed, 1 insertion(+)
diff --git a/clang/test/SemaTemplate/find-unexpanded-packs.cpp b/clang/test/SemaTemplate/find-unexpanded-packs.cpp
index ae989c68b50e22..5bb9fb1d6cde09 100644
--- a/clang/test/SemaTemplate/find-unexpanded-packs.cpp
+++ b/clang/test/SemaTemplate/find-unexpanded-packs.cpp
@@ -162,6 +162,7 @@ template void HiddenPack<int, float>();
template<typename ...Ts> void HiddenPackInvalid() {
Int<Ts>(); // expected-error {{unexpanded}}
Int<Ts>{}; // expected-error {{unexpanded}}
+ Int<Ts>({}); // expected-error {{unexpanded}} expected-error {{cannot initialize non-class type}}
Class<Ts>(); // expected-error {{unexpanded}}
Class<Ts>{}; // expected-error {{unexpanded}}
}
More information about the cfe-commits
mailing list