Skip to content

Commit 9a521e2

Browse files
committed
[clang][Interp] Fix primitive lambda capture defaults
We need to use InitField here, not SetField.
1 parent 8a65ee8 commit 9a521e2

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

clang/lib/AST/Interp/ByteCodeExprGen.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2025,7 +2025,7 @@ bool ByteCodeExprGen<Emitter>::VisitLambdaExpr(const LambdaExpr *E) {
20252025
if (!this->visit(Init))
20262026
return false;
20272027

2028-
if (!this->emitSetField(*T, F.Offset, E))
2028+
if (!this->emitInitField(*T, F.Offset, E))
20292029
return false;
20302030
} else {
20312031
if (!this->emitDupPtr(E))

clang/test/AST/Interp/lambda.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,3 +248,19 @@ namespace ns2_capture_this_byval {
248248
constexpr auto L = S{5}.f(S{10});
249249
static_assert(L(S{100}) == 115, "");
250250
} // end test_captures_1::ns2_capture_this_byval
251+
252+
namespace CaptureDefaults {
253+
struct S {
254+
int x;
255+
};
256+
257+
constexpr auto f = [x = S{10}]() {
258+
return x.x;
259+
};
260+
static_assert(f() == 10, "");
261+
262+
constexpr auto f2 = [x = 3]() {
263+
return x;
264+
};
265+
static_assert(f2() == 3, "");
266+
}

0 commit comments

Comments
 (0)