From 0505321691aa39105ecd2f92bb64cdaa932fbf08 Mon Sep 17 00:00:00 2001 From: Fariborz Jahanian Date: Tue, 1 Nov 2011 18:57:34 +0000 Subject: [PATCH] Find copy constructor needed to copy an rvalue reference c++ object into block descriptor. // rdar://9971124 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@143475 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Sema/SemaExpr.cpp | 5 ++++- .../CodeGenCXX/block-rvalue-reference-capture.cpp | 15 +++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp index 61766a88c0..d4d08703d3 100644 --- a/lib/Sema/SemaExpr.cpp +++ b/lib/Sema/SemaExpr.cpp @@ -1304,7 +1304,10 @@ static CaptureResult shouldCaptureValueReference(Sema &S, SourceLocation loc, // Okay, we descended all the way to the block that defines the variable. // Actually try to capture it. QualType type = var->getType(); - + + if (type->isRValueReferenceType()) + type = type->getPointeeType(); + // Prohibit variably-modified types. if (type->isVariablyModifiedType()) { S.Diag(loc, diag::err_ref_vm_type); diff --git a/test/CodeGenCXX/block-rvalue-reference-capture.cpp b/test/CodeGenCXX/block-rvalue-reference-capture.cpp index df99e42177..997e14f851 100644 --- a/test/CodeGenCXX/block-rvalue-reference-capture.cpp +++ b/test/CodeGenCXX/block-rvalue-reference-capture.cpp @@ -14,3 +14,18 @@ int main() { // CHECK: [[C:%.*]] = getelementptr inbounds <{ {{.*}} i32 }>* [[B]] // CHECK: [[R:%.*]] = load i32* [[C]], align 4 // CHECK: ret i32 [[R]] + +class S { +public: + S (const S &); + S(int); + int field; +}; + +int func(S && rv) +{ + return ^{ return rv.field; }(); +} + +// CHECK: define i32 @_Z4funcO1S +// CHECK: call void @_ZN1SC1ERKS_ -- 2.40.0