diff --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp b/clang/lib/AST/Interp/ByteCodeExprGen.cpp index b9318fbd9ae9e6..630fdb60c35182 100644 --- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp +++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp @@ -2025,7 +2025,7 @@ bool ByteCodeExprGen::VisitLambdaExpr(const LambdaExpr *E) { if (!this->visit(Init)) return false; - if (!this->emitSetField(*T, F.Offset, E)) + if (!this->emitInitField(*T, F.Offset, E)) return false; } else { if (!this->emitDupPtr(E)) diff --git a/clang/test/AST/Interp/lambda.cpp b/clang/test/AST/Interp/lambda.cpp index d056bb304eeb30..77e035ce254703 100644 --- a/clang/test/AST/Interp/lambda.cpp +++ b/clang/test/AST/Interp/lambda.cpp @@ -248,3 +248,19 @@ namespace ns2_capture_this_byval { constexpr auto L = S{5}.f(S{10}); static_assert(L(S{100}) == 115, ""); } // end test_captures_1::ns2_capture_this_byval + +namespace CaptureDefaults { + struct S { + int x; + }; + + constexpr auto f = [x = S{10}]() { + return x.x; + }; + static_assert(f() == 10, ""); + + constexpr auto f2 = [x = 3]() { + return x; + }; + static_assert(f2() == 3, ""); +}