Skip to content

Commit 85cedd8

Browse files
committed
[clang][Interp] Ignore incomplete records when visiting lambdas
We need them to be complete so we have knowledge about all the lambda captures.
1 parent e869549 commit 85cedd8

File tree

3 files changed

+14
-0
lines changed

3 files changed

+14
-0
lines changed

clang/lib/AST/Interp/ByteCodeEmitter.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,11 @@ Function *ByteCodeEmitter::compileFunc(const FunctionDecl *FuncDecl) {
9393

9494
// Set up lambda capture to closure record field mapping.
9595
if (isLambdaCallOperator(MD)) {
96+
// The parent record needs to be complete, we need to know about all
97+
// the lambda captures.
98+
if (!MD->getParent()->isCompleteDefinition())
99+
return nullptr;
100+
96101
const Record *R = P.getOrCreateRecord(MD->getParent());
97102
llvm::DenseMap<const ValueDecl *, FieldDecl *> LC;
98103
FieldDecl *LTC;

clang/lib/AST/Interp/Context.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ bool Context::isPotentialConstantExpr(State &Parent, const FunctionDecl *FD) {
3131
if (!Func || !Func->hasBody())
3232
Func = Compiler<ByteCodeEmitter>(*this, *P).compileFunc(FD);
3333

34+
if (!Func)
35+
return false;
36+
3437
APValue DummyResult;
3538
if (!Run(Parent, Func, DummyResult))
3639
return false;

clang/test/AST/Interp/lambda.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,3 +280,9 @@ namespace InvalidCapture {
280280
} ();
281281
}
282282
}
283+
284+
constexpr int fn() {
285+
int Capture = 42;
286+
return [=]() constexpr { return Capture; }();
287+
}
288+
static_assert(fn() == 42, "");

0 commit comments

Comments
 (0)