Skip to content

Commit d0e9101

Browse files
authored
PR for #79568 (#80120)
Backporting #79568 to clang 18.
1 parent 024f45e commit d0e9101

File tree

3 files changed

+29
-2
lines changed

3 files changed

+29
-2
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1054,6 +1054,11 @@ Bug Fixes to C++ Support
10541054
Fixes (`#78830 <https://github.com/llvm/llvm-project/issues/78830>`_)
10551055
Fixes (`#60085 <https://github.com/llvm/llvm-project/issues/60085>`_)
10561056

1057+
1058+
- Fixed a bug where variables referenced by requires-clauses inside
1059+
nested generic lambdas were not properly injected into the constraint scope.
1060+
(`#73418 <https://github.com/llvm/llvm-project/issues/73418>`_)
1061+
10571062
- Fix incorrect code generation caused by the object argument of ``static operator()`` and ``static operator[]`` calls not being evaluated.
10581063
Fixes (`#67976 <https://github.com/llvm/llvm-project/issues/67976>`_)
10591064

clang/lib/Sema/SemaConcept.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -612,8 +612,12 @@ bool Sema::SetupConstraintScope(
612612

613613
// If this is a member function, make sure we get the parameters that
614614
// reference the original primary template.
615-
if (const auto *FromMemTempl =
616-
PrimaryTemplate->getInstantiatedFromMemberTemplate()) {
615+
// We walk up the instantiated template chain so that nested lambdas get
616+
// handled properly.
617+
for (FunctionTemplateDecl *FromMemTempl =
618+
PrimaryTemplate->getInstantiatedFromMemberTemplate();
619+
FromMemTempl;
620+
FromMemTempl = FromMemTempl->getInstantiatedFromMemberTemplate()) {
617621
if (addInstantiatedParametersToScope(FD, FromMemTempl->getTemplatedDecl(),
618622
Scope, MLTAL))
619623
return true;

clang/test/SemaTemplate/concepts-lambda.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,3 +149,21 @@ void foo() {
149149
auto caller = make_caller.operator()<&S1::f1>();
150150
}
151151
} // namespace ReturnTypeRequirementInLambda
152+
153+
namespace GH73418 {
154+
void foo() {
155+
int x;
156+
[&x](auto) {
157+
return [](auto y) {
158+
return [](auto obj, auto... params)
159+
requires requires {
160+
sizeof...(params);
161+
[](auto... pack) {
162+
return sizeof...(pack);
163+
}(params...);
164+
}
165+
{ return false; }(y);
166+
}(x);
167+
}(x);
168+
}
169+
} // namespace GH73418

0 commit comments

Comments
 (0)