The fix for aggregate initialization (std::make_unique<Foo>(Foo {1, 2}) needs
to see Foo copy/move constructor, otherwise we will have a compiler error. So we
only emit the check warning.
Details
- Reviewers
JonasToth aaron.ballman alexfh - Commits
- rGdbfa9c3e0a34: [clang-tidy] Don't generate incorrect fixes for class with deleted copy…
rCTE347537: [clang-tidy] Don't generate incorrect fixes for class with deleted copy…
rL347537: [clang-tidy] Don't generate incorrect fixes for class with deleted copy…
Diff Detail
- Repository
- rL LLVM
Event Timeline
Does make_unique require the copy constructor if it could move?
And would the same argument apply to the move-constructors as the arguments are forwarded?
What would happen in the obscure case of a public copy-constructor, but private move-constructor (not saying it makes sense :))
clang-tidy/modernize/MakeSmartPtrCheck.cpp | ||
---|---|---|
380 ↗ | (On Diff #174736) | typo: s/consturctor/constructor/ |
test/clang-tidy/modernize-make-unique.cpp | ||
35 ↗ | (On Diff #174736) | please add a case for the private copy-constructor as well. |
Thanks for the review.
No, in that case, move constructor will be used. I have updated the patch to include these cases.
And would the same argument apply to the move-constructors as the arguments are forwarded?
What would happen in the obscure case of a public copy-constructor, but private move-constructor (not saying it makes sense :))
This depends. The rule is complicated, for some cases it works, for other cases, it won't work.
test/clang-tidy/modernize-make-unique.cpp | ||
---|---|---|
35 ↗ | (On Diff #174736) | Added more tests. |
IMHO this patch is fine, but i think a language expert (not me :D) should take a look (@aaron.ballman ?) as its complicated :)
Generally LGTM with a few small nits.
clang-tidy/modernize/MakeSmartPtrCheck.cpp | ||
---|---|---|
379 ↗ | (On Diff #174760) | requires to see -> needs to see |
383 ↗ | (On Diff #174760) | Don't use auto here. |
384 ↗ | (On Diff #174760) | How about: if (llvm::find_if(RD->ctors(), [](const CXXConstructorDecl *CD) { return Ctor->isCopyOrMoveConstructor() && (Ctor->isDeleted() || Ctor->getAccess() == AS_private); })) return false; |