[PATCH] D49215: [analyzer] Admit that some copy/move constructors have more than one argument.

Artem Dergachev via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Jul 11 18:48:15 PDT 2018


NoQ created this revision.
NoQ added reviewers: dcoughlin, xazax.hun, a.sidorin, george.karpenkov, szepet, rnkovacs.
Herald added subscribers: cfe-commits, mikhail.ramalho, baloghadamsoftware.

Copy/move constructors may have additional default arguments and still be treated as normal copy/move constructors. Copy elision code expected this to not be a thing, for no particular reason. Remove the premature assertion.

Hopefully addresses the crash posted by @alexfh in http://lists.llvm.org/pipermail/cfe-commits/Week-of-Mon-20180702/233796.html


Repository:
  rC Clang

https://reviews.llvm.org/D49215

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


Index: test/Analysis/cfg-rich-constructors.cpp
===================================================================
--- test/Analysis/cfg-rich-constructors.cpp
+++ test/Analysis/cfg-rich-constructors.cpp
@@ -937,3 +937,15 @@
   E e = E(D());
 }
 } // end namespace argument_constructors
+
+namespace copy_elision_with_extra_arguments {
+class C {
+public:
+  C();
+  C(const C &c, int x = 0);
+};
+
+void testCopyElisionWhenCopyConstructorHasExtraArguments() {
+  C c = C();
+}
+} // namespace copy_elision_with_extra_arguments
Index: lib/Analysis/CFG.cpp
===================================================================
--- lib/Analysis/CFG.cpp
+++ lib/Analysis/CFG.cpp
@@ -1298,7 +1298,6 @@
     // 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));
     }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D49215.155104.patch
Type: text/x-patch
Size: 969 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180712/77d4b2eb/attachment-0001.bin>


More information about the cfe-commits mailing list