Look through parentheses when deciding whether an expr is a temporary object. Fixes PR8683.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@120247 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Anders Carlsson 2010-11-28 16:40:49 +00:00
Родитель fbfdb20240
Коммит f8b3015060
2 изменённых файлов: 26 добавлений и 4 удалений

Просмотреть файл

@ -1804,7 +1804,7 @@ bool Expr::isDefaultArgument() const {
/// \brief Skip over any no-op casts and any temporary-binding
/// expressions.
static const Expr *skipTemporaryBindingsAndNoOpCasts(const Expr *E) {
static const Expr *skipTemporaryBindingsNoOpCastsAndParens(const Expr *E) {
while (const ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(E)) {
if (ICE->getCastKind() == CK_NoOp)
E = ICE->getSubExpr();
@ -1822,7 +1822,7 @@ static const Expr *skipTemporaryBindingsAndNoOpCasts(const Expr *E) {
break;
}
return E;
return E->IgnoreParens();
}
/// isTemporaryObject - Determines if this expression produces a
@ -1831,7 +1831,7 @@ bool Expr::isTemporaryObject(ASTContext &C, const CXXRecordDecl *TempTy) const {
if (!C.hasSameUnqualifiedType(getType(), C.getTypeDeclType(TempTy)))
return false;
const Expr *E = skipTemporaryBindingsAndNoOpCasts(this);
const Expr *E = skipTemporaryBindingsNoOpCastsAndParens(this);
// Temporaries are by definition pr-values of class type.
if (!E->Classify(C).isPRValue()) {

Просмотреть файл

@ -31,3 +31,25 @@ namespace no_elide_base {
// CHECK: ret void
}
}
// PR8683.
namespace PR8683 {
struct A {
A();
A(const A&);
A& operator=(const A&);
};
struct B {
A a;
};
void f() {
// Verify that we don't mark the copy constructor in this expression as elidable.
// CHECK: call void @_ZN6PR86831AC1ERKS0_
A a = (B().a);
}
}