Skip to content

Commit 19d97fc

Browse files
committed
Limit the scope to lambda conversion function only
1 parent 4235e44 commit 19d97fc

File tree

3 files changed

+37
-1
lines changed

3 files changed

+37
-1
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,9 @@ Bug Fixes to C++ Support
275275
(`#82258 <https://github.com/llvm/llvm-project/issues/82258>`_)
276276
- Correctly immediate-escalate lambda conversion functions.
277277
(`#82258 <https://github.com/llvm/llvm-project/issues/82258>`_)
278+
- Fixed a crash while checking constraints of a trailing requires-expression of a lambda, that the
279+
expression references to an entity declared outside of the lambda. This is a reduction from
280+
(`#64808 <https://github.com/llvm/llvm-project/issues/64808>`_).
278281

279282
Bug Fixes to AST Handling
280283
^^^^^^^^^^^^^^^^^^^^^^^^^

clang/lib/Sema/SemaConcept.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -691,11 +691,15 @@ bool Sema::CheckFunctionConstraints(const FunctionDecl *FD,
691691
// A lambda conversion operator has the same constraints as the call operator
692692
// and constraints checking relies on whether we are in a lambda call operator
693693
// (and may refer to its parameters), so check the call operator instead.
694+
// Note that the declarations outside of the lambda should also be
695+
// incorporated. Turning on the 'ForOverloadResolution' flag results in the
696+
// LocalInstantiationScope not looking into its parents, but we can still
697+
// access Decls from the parents while building a lambda RAII scope later.
694698
if (const auto *MD = dyn_cast<CXXConversionDecl>(FD);
695699
MD && isLambdaConversionOperator(const_cast<CXXConversionDecl *>(MD)))
696700
return CheckFunctionConstraints(MD->getParent()->getLambdaCallOperator(),
697701
Satisfaction, UsageLoc,
698-
ForOverloadResolution);
702+
/*ShouldAddDeclsFromParentScope=*/true);
699703

700704
DeclContext *CtxToSave = const_cast<FunctionDecl *>(FD);
701705

clang/test/SemaTemplate/concepts.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1085,3 +1085,32 @@ template void Struct<void>::bar<>();
10851085
template int Struct<void>::field<1, 2>;
10861086

10871087
}
1088+
1089+
namespace GH64808 {
1090+
1091+
template <class T> struct basic_sender {
1092+
T func;
1093+
basic_sender(T) : func(T()) {}
1094+
};
1095+
1096+
auto a = basic_sender{[](auto... __captures) {
1097+
return []() // #note-a-1
1098+
requires((__captures, ...), false) // #note-a-2
1099+
{};
1100+
}()};
1101+
1102+
auto b = basic_sender{[](auto... __captures) {
1103+
return []()
1104+
requires([](int, double) { return true; }(decltype(__captures)()...))
1105+
{};
1106+
}(1, 2.33)};
1107+
1108+
void foo() {
1109+
a.func();
1110+
// expected-error@-1{{no matching function for call}}
1111+
// expected-note@#note-a-1{{constraints not satisfied}}
1112+
// expected-note@#note-a-2{{evaluated to false}}
1113+
b.func();
1114+
}
1115+
1116+
} // namespace GH64808

0 commit comments

Comments
 (0)