]> granicus.if.org Git - clang/commitdiff
Sema::MaybeBindToTemporary() shouldn't treat any expression returning
authorDouglas Gregor <dgregor@apple.com>
Tue, 8 Feb 2011 02:14:35 +0000 (02:14 +0000)
committerDouglas Gregor <dgregor@apple.com>
Tue, 8 Feb 2011 02:14:35 +0000 (02:14 +0000)
a glvalue as a temporary. Previously, we were enumerating all of the
cases that coul return glvalues and might be called with
Sema::MaybeBindToTemporary(), but that was gross and we missed the
Objective-C property reference case.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@125070 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaExprCXX.cpp
test/SemaObjCXX/properties.mm [new file with mode: 0644]

index 81031a54eed1d0cfe1447a214cee224852395662..ea1ad51e9d6d0ff4dcc4a82ac1ef63dbd537dc8f 100644 (file)
@@ -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 (file)
index 0000000..f148b33
--- /dev/null
@@ -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
+