llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: Harlen Batagelo (hbatagelo)
<details>
<summary>Changes</summary>
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.
---
Full diff: https://github.com/llvm/llvm-project/pull/236838.diff
2 Files Affected:
- (modified) clang/lib/Sema/SemaTemplateVariadic.cpp (+7)
- (modified) clang/test/SemaTemplate/find-unexpanded-packs.cpp (+1)
``````````diff
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);
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}}
}
``````````
</details>
https://github.com/llvm/llvm-project/pull/236838
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits