[clang] 6b0b306 - Fix regression from Deferred Concepts with lambda in var init
Erich Keane via cfe-commits
cfe-commits at lists.llvm.org
Tue Sep 27 06:32:49 PDT 2022
Author: Erich Keane
Date: 2022-09-27T06:32:39-07:00
New Revision: 6b0b306e6221ba3f8f02944b8e5a8140f4d52324
URL: https://github.com/llvm/llvm-project/commit/6b0b306e6221ba3f8f02944b8e5a8140f4d52324
DIFF: https://github.com/llvm/llvm-project/commit/6b0b306e6221ba3f8f02944b8e5a8140f4d52324.diff
LOG: 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.
Added:
clang/test/SemaTemplate/concepts-lambda.cpp
Modified:
clang/lib/Sema/SemaConcept.cpp
Removed:
################################################################################
diff --git a/clang/lib/Sema/SemaConcept.cpp b/clang/lib/Sema/SemaConcept.cpp
index 7426b553fcfb8..6ad418599d368 100644
--- a/clang/lib/Sema/SemaConcept.cpp
+++ b/clang/lib/Sema/SemaConcept.cpp
@@ -529,9 +529,16 @@ bool Sema::CheckFunctionConstraints(const FunctionDecl *FD,
return false;
}
- ContextRAII SavedContext{
- *this, cast<DeclContext>(
- const_cast<FunctionDecl *>(FD)->getNonClosureContext())};
+ DeclContext *CtxToSave = const_cast<FunctionDecl *>(FD);
+
+ while (isLambdaCallOperator(CtxToSave) || FD->isTransparentContext()) {
+ if (isLambdaCallOperator(CtxToSave))
+ CtxToSave = CtxToSave->getParent()->getParent();
+ else
+ CtxToSave = CtxToSave->getNonTransparentContext();
+ }
+
+ ContextRAII SavedContext{*this, CtxToSave};
LocalInstantiationScope Scope(*this, !ForOverloadResolution ||
isLambdaCallOperator(FD));
llvm::Optional<MultiLevelTemplateArgumentList> MLTAL =
diff --git a/clang/test/SemaTemplate/concepts-lambda.cpp b/clang/test/SemaTemplate/concepts-lambda.cpp
new file mode 100644
index 0000000000000..5309a6009893c
--- /dev/null
+++ b/clang/test/SemaTemplate/concepts-lambda.cpp
@@ -0,0 +1,15 @@
+// RUN: %clang_cc1 -std=c++20 -verify %s
+// expected-no-diagnostics
+
+namespace GH57945 {
+ template<typename T>
+ concept c = true;
+
+ template<typename>
+ auto f = []() requires c<void> {
+ };
+
+ void g() {
+ f<int>();
+ };
+}
More information about the cfe-commits
mailing list