]> granicus.if.org Git - clang/commitdiff
Fix a slight oversight in computing whether a copy constructor is elidable.
authorEli Friedman <eli.friedman@gmail.com>
Sun, 6 Dec 2009 09:26:33 +0000 (09:26 +0000)
committerEli Friedman <eli.friedman@gmail.com>
Sun, 6 Dec 2009 09:26:33 +0000 (09:26 +0000)
Fixes PR5695.

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

lib/Sema/SemaDeclCXX.cpp
test/CodeGenCXX/elide-call-reference.cpp [new file with mode: 0644]

index 652b92db5ed6c7cbe50f7e573a9aab1746902244..e1150955666a74d8ecf4f6997a67764e7fcc3d30 100644 (file)
@@ -3369,8 +3369,10 @@ Sema::BuildCXXConstructExpr(SourceLocation ConstructLoc, QualType DeclInitType,
     if (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(E))
       if (ICE->getCastKind() == CastExpr::CK_NoOp)
         E = ICE->getSubExpr();
-    
-    if (isa<CallExpr>(E) || isa<CXXTemporaryObjectExpr>(E))
+
+    if (CallExpr *CE = dyn_cast<CallExpr>(E))
+      Elidable = !CE->getCallReturnType()->isReferenceType();
+    else if (isa<CXXTemporaryObjectExpr>(E))
       Elidable = true;
   }
 
diff --git a/test/CodeGenCXX/elide-call-reference.cpp b/test/CodeGenCXX/elide-call-reference.cpp
new file mode 100644 (file)
index 0000000..863e69c
--- /dev/null
@@ -0,0 +1,11 @@
+// RUN: clang-cc %s -emit-llvm -o - | FileCheck %s
+// PR5695
+
+struct A { A(const A&); ~A(); };
+A& a();
+void b() {
+  A x = a();
+}
+
+// CHECK: call void @_ZN1AC1ERKS_
+// CHECK: call void @_ZN1AD1Ev