]> granicus.if.org Git - clang/commitdiff
[CFG] [analyzer] Allow elidable copies to have more than one arguments.
authorArtem Dergachev <artem.dergachev@gmail.com>
Tue, 17 Jul 2018 00:57:57 +0000 (00:57 +0000)
committerArtem Dergachev <artem.dergachev@gmail.com>
Tue, 17 Jul 2018 00:57:57 +0000 (00:57 +0000)
Copy-constructors and move-constructors may have default arguments. It is
incorrect to assert that they only have one argument, i.e. the reference to the
object being copied or moved. Remove the assertion.

Differential Revision: https://reviews.llvm.org/D49215

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

lib/Analysis/CFG.cpp
test/Analysis/cfg-rich-constructors.cpp

index 62803f4ba566e3dc99a53b5aff6219918e1acf3c..b895087e51174da85d3e7cd5726ae91d5fd611aa 100644 (file)
@@ -1263,7 +1263,6 @@ void CFGBuilder::findConstructionContexts(
     // Support pre-C++17 copy elision AST.
     auto *CE = cast<CXXConstructExpr>(Child);
     if (BuildOpts.MarkElidedCXXConstructors && CE->isElidable()) {
-      assert(CE->getNumArgs() == 1);
       findConstructionContexts(withExtraLayer(CE), CE->getArg(0));
     }
 
index 3944141b9265d6f1ea75de69ee51a2ad86bb4274..ce3e5f84baef0576c5d7da0a39b8d5cfaee274d6 100644 (file)
@@ -878,3 +878,26 @@ void passArgumentWithDestructorByReference() {
   useDByReference(D());
 }
 } // end namespace argument_constructors
+
+namespace copy_elision_with_extra_arguments {
+class C {
+public:
+  C();
+  C(const C &c, int x = 0);
+};
+
+// CHECK: void testCopyElisionWhenCopyConstructorHasExtraArguments()
+// CHECK:        [B1]
+// CXX11-ELIDE-NEXT:     1: copy_elision_with_extra_arguments::C() (CXXConstructExpr, [B1.3], [B1.5], class copy_elision_with_extra_arguments::C)
+// CXX11-NOELIDE-NEXT:     1: copy_elision_with_extra_arguments::C() (CXXConstructExpr, [B1.3], class copy_elision_with_extra_arguments::C)
+// CXX11-NEXT:     2: [B1.1] (ImplicitCastExpr, NoOp, const class copy_elision_with_extra_arguments::C)
+// CXX11-NEXT:     3: [B1.2]
+// CXX11-NEXT:     4:
+// CXX11-NEXT:     5: [B1.3] (CXXConstructExpr, [B1.6], class copy_elision_with_extra_arguments::C)
+// CXX11-NEXT:     6: copy_elision_with_extra_arguments::C c = copy_elision_with_extra_arguments::C();
+// CXX17-NEXT:     1: copy_elision_with_extra_arguments::C() (CXXConstructExpr, [B1.2], class copy_elision_with_extra_arguments::C)
+// CXX17-NEXT:     2: copy_elision_with_extra_arguments::C c = copy_elision_with_extra_arguments::C();
+void testCopyElisionWhenCopyConstructorHasExtraArguments() {
+  C c = C();
+}
+} // namespace copy_elision_with_extra_arguments