]> granicus.if.org Git - clang/commitdiff
Look through parentheses when deciding whether an expr is a temporary object. Fixes...
authorAnders Carlsson <andersca@mac.com>
Sun, 28 Nov 2010 16:40:49 +0000 (16:40 +0000)
committerAnders Carlsson <andersca@mac.com>
Sun, 28 Nov 2010 16:40:49 +0000 (16:40 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@120247 91177308-0d34-0410-b5e6-96231b3b80d8

lib/AST/Expr.cpp
test/CodeGenCXX/copy-constructor-elim-2.cpp

index 3e3792e21fe727119ebc07558c0ea911bb75f767..3a112a7e073ffba6ff311d48a2e65f515de5c793 100644 (file)
@@ -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();
@@ -1821,8 +1821,8 @@ static const Expr *skipTemporaryBindingsAndNoOpCasts(const Expr *E) {
     else
       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()) {
index 73e9b94bcd11d0159185c382cc3dcf4eb6f158e2..563676f6e36fa88d61e317556ad0da4fbc21c8b7 100644 (file)
@@ -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);
+}
+
+}