Skip to content

Commit 6b0b306

Browse files
author
Erich Keane
committed
Fix regression from Deferred Concepts with lambda in var init
As reported in GH #57945, this would crash because the decl context for the lambda was being loaded via 'getNonClosureContext', which only gets CODE contexts, so a global lambda was getting 'nullptr' here instead. This patch does some work to make sure we get a valid/valuable declcontext here instead.
1 parent 7ccfaec commit 6b0b306

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

clang/lib/Sema/SemaConcept.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -529,9 +529,16 @@ bool Sema::CheckFunctionConstraints(const FunctionDecl *FD,
529529
return false;
530530
}
531531

532-
ContextRAII SavedContext{
533-
*this, cast<DeclContext>(
534-
const_cast<FunctionDecl *>(FD)->getNonClosureContext())};
532+
DeclContext *CtxToSave = const_cast<FunctionDecl *>(FD);
533+
534+
while (isLambdaCallOperator(CtxToSave) || FD->isTransparentContext()) {
535+
if (isLambdaCallOperator(CtxToSave))
536+
CtxToSave = CtxToSave->getParent()->getParent();
537+
else
538+
CtxToSave = CtxToSave->getNonTransparentContext();
539+
}
540+
541+
ContextRAII SavedContext{*this, CtxToSave};
535542
LocalInstantiationScope Scope(*this, !ForOverloadResolution ||
536543
isLambdaCallOperator(FD));
537544
llvm::Optional<MultiLevelTemplateArgumentList> MLTAL =
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// RUN: %clang_cc1 -std=c++20 -verify %s
2+
// expected-no-diagnostics
3+
4+
namespace GH57945 {
5+
template<typename T>
6+
concept c = true;
7+
8+
template<typename>
9+
auto f = []() requires c<void> {
10+
};
11+
12+
void g() {
13+
f<int>();
14+
};
15+
}

0 commit comments

Comments
 (0)