diff options
author | Piotr Padlewski <piotr.padlewski@gmail.com> | 2016-08-31 00:06:55 +0000 |
---|---|---|
committer | Piotr Padlewski <piotr.padlewski@gmail.com> | 2016-08-31 00:06:55 +0000 |
commit | d57be707b88beb31bcf75b51ca6c381b17dd8249 (patch) | |
tree | 207c86cda4382ec4e2f6df1b697468ed7b4a3481 /clang-tools-extra/test/clang-tidy/modernize-make-unique.cpp | |
parent | 3f8f7840bf12ffa4bfd558e5115acbd66b39280a (diff) | |
download | bcm5719-llvm-d57be707b88beb31bcf75b51ca6c381b17dd8249.tar.gz bcm5719-llvm-d57be707b88beb31bcf75b51ca6c381b17dd8249.zip |
[clang-tidy] modernize-make-{smart_ptr} private ctor bugfix
Summary:
Bugfix for 27321. When the constructor of stored pointer
type is private then it is invalid to change it to
make_shared or make_unique.
Reviewers: alexfh, aaron.ballman, hokein
Subscribers: cfe-commits
Differential Revision: https://reviews.llvm.org/D23343
llvm-svn: 280180
Diffstat (limited to 'clang-tools-extra/test/clang-tidy/modernize-make-unique.cpp')
-rw-r--r-- | clang-tools-extra/test/clang-tidy/modernize-make-unique.cpp | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/clang-tools-extra/test/clang-tidy/modernize-make-unique.cpp b/clang-tools-extra/test/clang-tidy/modernize-make-unique.cpp index 842955486a1..31157347736 100644 --- a/clang-tools-extra/test/clang-tidy/modernize-make-unique.cpp +++ b/clang-tools-extra/test/clang-tidy/modernize-make-unique.cpp @@ -103,6 +103,38 @@ void basic() { std::unique_ptr<int> Placement = std::unique_ptr<int>(new (PInt) int{3}); } +// Calling make_smart_ptr from within a member function of a type with a +// private or protected constructor would be ill-formed. +class Private { +private: + Private(int z) {} + +public: + Private() {} + void create() { + auto callsPublic = std::unique_ptr<Private>(new Private); + // CHECK-MESSAGES: :[[@LINE-1]]:24: warning: use std::make_unique instead + // CHECK-FIXES: auto callsPublic = std::make_unique<Private>(); + auto ptr = std::unique_ptr<Private>(new Private(42)); + } + + virtual ~Private(); +}; + +class Protected { +protected: + Protected() {} + +public: + Protected(int, int) {} + void create() { + auto callsPublic = std::unique_ptr<Protected>(new Protected(1, 2)); + // CHECK-MESSAGES: :[[@LINE-1]]:24: warning: use std::make_unique instead + // CHECK-FIXES: auto callsPublic = std::make_unique<Protected>(1, 2); + auto ptr = std::unique_ptr<Protected>(new Protected); + } +}; + void initialization(int T, Base b) { // Test different kinds of initialization of the pointee. |