From 289a0d810fb35c960f33c33ff8b7185c11d04d5f Mon Sep 17 00:00:00 2001 From: Fariborz Jahanian Date: Wed, 16 Oct 2013 17:51:43 +0000 Subject: [PATCH] ObjectiveC++: support for passing C++11 style initialized temporaries to objc++ properties using property-dot syntax. // rdar://14654207 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@192819 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Sema/SemaPseudoObject.cpp | 10 ++++++++++ test/SemaObjCXX/properties.mm | 31 +++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/lib/Sema/SemaPseudoObject.cpp b/lib/Sema/SemaPseudoObject.cpp index 106250fe0f..af74f0d4a3 100644 --- a/lib/Sema/SemaPseudoObject.cpp +++ b/lib/Sema/SemaPseudoObject.cpp @@ -730,6 +730,16 @@ ExprResult ObjCPropertyOpBuilder::buildSet(Expr *op, SourceLocation opcLoc, op = opResult.take(); assert(op && "successful assignment left argument invalid?"); } + else if (OpaqueValueExpr *OVE = dyn_cast(op)) { + Expr *Initializer = OVE->getSourceExpr(); + // passing C++11 style initialized temporaries to objc++ properties + // requires special treatment by removing OpaqueValueExpr so type + // conversion takes place and adding the OpaqueValueExpr later on. + if (isa(Initializer) && + Initializer->getType()->isVoidType()) { + op = Initializer; + } + } } // Arguments. diff --git a/test/SemaObjCXX/properties.mm b/test/SemaObjCXX/properties.mm index 36f59b650c..7bb4fab3d3 100644 --- a/test/SemaObjCXX/properties.mm +++ b/test/SemaObjCXX/properties.mm @@ -172,3 +172,34 @@ namespace test10 { @implementation PropertyOfItself @synthesize x; @end + +// rdar://14654207 +struct CGSize { + double width; + double height; +}; +typedef struct CGSize CGSize; + +struct CGRect { + CGSize origin; + CGSize size; +}; +typedef struct CGRect CGRect; + +typedef CGRect NSRect; +void HappySetFrame(NSRect frame) {} + +__attribute__((objc_root_class)) +@interface NSObject +@property CGRect frame; +@end + +@implementation NSObject +- (void) nothing +{ + HappySetFrame({{0,0}, {13,14}}); + [self setFrame: {{0,0}, {13,14}}]; + self.frame = {{0,0}, {13,14}}; + self.frame = (CGRect){{3,5}, {13,14}}; +} +@end -- 2.40.0