OSDN Git Service

[clang-tidy] Omit std::make_unique/make_shared for default initialization.
authorChris Kennelly <ckennelly@ckennelly.com>
Thu, 29 Oct 2020 02:45:09 +0000 (22:45 -0400)
committerChris Kennelly <ckennelly@ckennelly.com>
Tue, 8 Dec 2020 15:34:17 +0000 (10:34 -0500)
commit8d2c095e5a6bd34f8bb5cffd5c57c8deea5b8647
tree586f031bc484c100f049d6c52cb5ee76f70bee0b
parent03e675fd128bed754454fc176357ad0ec6660c47
[clang-tidy] Omit std::make_unique/make_shared for default initialization.

This extends the check for default initialization in arrays added in
547f89d6070 to include scalar types and exclude them from the suggested fix for
make_unique/make_shared.

Rewriting std::unique_ptr<int>(new int) as std::make_unique<int>() (or for
other, similar trivial T) switches from default initialization to value
initialization, a performance regression for trivial T.  For these use cases,
std::make_unique_for_overwrite is more suitable alternative.

Reviewed By: hokein

Differential Revision: https://reviews.llvm.org/D90392
clang-tools-extra/clang-tidy/modernize/MakeSmartPtrCheck.cpp
clang-tools-extra/clang-tidy/modernize/MakeSmartPtrCheck.h
clang-tools-extra/docs/clang-tidy/checks/modernize-make-shared.rst
clang-tools-extra/docs/clang-tidy/checks/modernize-make-unique.rst
clang-tools-extra/test/clang-tidy/checkers/modernize-make-shared.cpp
clang-tools-extra/test/clang-tidy/checkers/modernize-make-unique-default-init.cpp [new file with mode: 0644]
clang-tools-extra/test/clang-tidy/checkers/modernize-make-unique.cpp