Skip to content

Commit 868007a

Browse files
authored
[clang][Sema] Avoid non-empty unexpanded pack assertion for FunctionParmPackExpr (#69224)
Closes #61460. We have FunctionParmPackExpr that serves as the unexpanded expression but from which the visitor collects none, which may lead to assertion failure during the template instantiation.
1 parent 285a229 commit 868007a

File tree

3 files changed

+22
-0
lines changed

3 files changed

+22
-0
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -553,6 +553,8 @@ Bug Fixes in This Version
553553
Fixes (`#67687 <https://github.com/llvm/llvm-project/issues/67687>`_)
554554
- Fix crash from constexpr evaluator evaluating uninitialized arrays as rvalue.
555555
Fixes (`#67317 <https://github.com/llvm/llvm-project/issues/67317>`_)
556+
- Fixed an issue that a benign assertion might hit when instantiating a pack expansion
557+
inside a lambda. (`#61460 <https://github.com/llvm/llvm-project/issues/61460>`_)
556558

557559
Bug Fixes to Compiler Builtins
558560
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

clang/lib/Sema/SemaTemplateVariadic.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,13 @@ bool Sema::DiagnoseUnexpandedParameterPack(Expr *E,
402402
if (!E->containsUnexpandedParameterPack())
403403
return false;
404404

405+
// CollectUnexpandedParameterPacksVisitor does not expect to see a
406+
// FunctionParmPackExpr, but diagnosing unexpected parameter packs may still
407+
// see such an expression in a lambda body.
408+
// We'll bail out early in this case to avoid triggering an assertion.
409+
if (isa<FunctionParmPackExpr>(E) && getEnclosingLambda())
410+
return false;
411+
405412
SmallVector<UnexpandedParameterPack, 2> Unexpanded;
406413
CollectUnexpandedParameterPacksVisitor(Unexpanded).TraverseStmt(E);
407414
assert(!Unexpanded.empty() && "Unable to find unexpanded parameter packs");

clang/test/SemaCXX/pr61460.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// RUN: %clang_cc1 -std=c++17 %s -fsyntax-only -verify
2+
3+
template <typename... Ts> void g(Ts... p1s) {
4+
(void)[&](auto... p2s) { ([&] { p1s; p2s; }, ...); };
5+
}
6+
7+
void f1() {
8+
g();
9+
}
10+
11+
template <typename... Ts> void g2(Ts... p1s) {
12+
(void)[&](auto... p2s) { [&] { p1s; p2s; }; }; // expected-error {{expression contains unexpanded parameter pack 'p2s'}}
13+
}

0 commit comments

Comments
 (0)