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
- rCTE Clang Tools Extra
- Build Status
Buildable 25311 Build 25310: arc lint + arc unit
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 | ||
---|---|---|
392 | typo: s/consturctor/constructor/ | |
test/clang-tidy/modernize-make-unique.cpp | ||
35 | 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 | 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 | ||
---|---|---|
391 | requires to see -> needs to see | |
395 | Don't use auto here. | |
396 | How about: if (llvm::find_if(RD->ctors(), [](const CXXConstructorDecl *CD) { return Ctor->isCopyOrMoveConstructor() && (Ctor->isDeleted() || Ctor->getAccess() == AS_private); })) return false; |
requires to see -> needs to see