aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/Sema/SemaExprCXX.cpp14
-rw-r--r--test/SemaObjCXX/properties.mm24
2 files changed, 27 insertions, 11 deletions
diff --git a/lib/Sema/SemaExprCXX.cpp b/lib/Sema/SemaExprCXX.cpp
index 81031a54ee..ea1ad51e9d 100644
--- a/lib/Sema/SemaExprCXX.cpp
+++ b/lib/Sema/SemaExprCXX.cpp
@@ -3370,17 +3370,9 @@ ExprResult Sema::MaybeBindToTemporary(Expr *E) {
if (!RT)
return Owned(E);
- // If this is the result of a call or an Objective-C message send expression,
- // our source might actually be a reference, in which case we shouldn't bind.
- if (CallExpr *CE = dyn_cast<CallExpr>(E)) {
- if (CE->getCallReturnType()->isReferenceType())
- return Owned(E);
- } else if (ObjCMessageExpr *ME = dyn_cast<ObjCMessageExpr>(E)) {
- if (const ObjCMethodDecl *MD = ME->getMethodDecl()) {
- if (MD->getResultType()->isReferenceType())
- return Owned(E);
- }
- }
+ // If the result is a glvalue, we shouldn't bind it.
+ if (E->Classify(Context).isGLValue())
+ return Owned(E);
// That should be enough to guarantee that this type is complete.
// If it has a trivial destructor, we can avoid the extra copy.
diff --git a/test/SemaObjCXX/properties.mm b/test/SemaObjCXX/properties.mm
new file mode 100644
index 0000000000..f148b3395d
--- /dev/null
+++ b/test/SemaObjCXX/properties.mm
@@ -0,0 +1,24 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+struct X {
+ void f() const;
+ ~X();
+};
+
+@interface A {
+ X x_;
+}
+
+- (const X&)x;
+- (void)setx:(const X&)other;
+@end
+
+@implementation A
+
+- (const X&)x { return x_; }
+- (void)setx:(const X&)other { x_ = other; }
+- (void)method {
+ self.x.f();
+}
+@end
+