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)); }
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)); }
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits