Sema::MaybeBindToTemporary() shouldn't treat any expression returning

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.

llvm-svn: 125070
This commit is contained in:
Douglas Gregor 2011-02-08 02:14:35 +00:00
parent bec0285d7f
commit a57a66e8d0
2 changed files with 27 additions and 11 deletions

View File

@ -3370,17 +3370,9 @@ ExprResult Sema::MaybeBindToTemporary(Expr *E) {
if (!RT) if (!RT)
return Owned(E); return Owned(E);
// If this is the result of a call or an Objective-C message send expression, // If the result is a glvalue, we shouldn't bind it.
// our source might actually be a reference, in which case we shouldn't bind. if (E->Classify(Context).isGLValue())
if (CallExpr *CE = dyn_cast<CallExpr>(E)) { return Owned(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);
}
}
// That should be enough to guarantee that this type is complete. // That should be enough to guarantee that this type is complete.
// If it has a trivial destructor, we can avoid the extra copy. // If it has a trivial destructor, we can avoid the extra copy.

View File

@ -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