diff options
author | Haojian Wu <hokein@google.com> | 2018-11-26 12:42:08 +0000 |
---|---|---|
committer | Haojian Wu <hokein@google.com> | 2018-11-26 12:42:08 +0000 |
commit | 77c56fffadacefcced1155a7490738ab1253b728 (patch) | |
tree | 2aa1ef3684662bba0348261b7b1fd7d0e21be8e9 | |
parent | 15b8cd919033a78a55256b2e7cda81de2b29c2e0 (diff) | |
download | bcm5719-llvm-77c56fffadacefcced1155a7490738ab1253b728.tar.gz bcm5719-llvm-77c56fffadacefcced1155a7490738ab1253b728.zip |
[clang-tidy] No warning for auto new expression in smart check
Summary: The fix for `auto` new expression is illegal.
Reviewers: aaron.ballman
Subscribers: xazax.hun, cfe-commits
Differential Revision: https://reviews.llvm.org/D54832
llvm-svn: 347551
-rw-r--r-- | clang-tools-extra/clang-tidy/modernize/MakeSmartPtrCheck.cpp | 3 | ||||
-rw-r--r-- | clang-tools-extra/test/clang-tidy/modernize-make-unique.cpp | 3 |
2 files changed, 6 insertions, 0 deletions
diff --git a/clang-tools-extra/clang-tidy/modernize/MakeSmartPtrCheck.cpp b/clang-tools-extra/clang-tidy/modernize/MakeSmartPtrCheck.cpp index c8d66cadd6d..15b88b8b353 100644 --- a/clang-tools-extra/clang-tidy/modernize/MakeSmartPtrCheck.cpp +++ b/clang-tools-extra/clang-tidy/modernize/MakeSmartPtrCheck.cpp @@ -120,6 +120,9 @@ void MakeSmartPtrCheck::check(const MatchFinder::MatchResult &Result) { if (New->getNumPlacementArgs() != 0) return; + // Skip when this is a new-expression with `auto`, e.g. new auto(1) + if (New->getType()->getPointeeType()->getContainedAutoType()) + return; // Be conservative for cases where we construct an array without any // initalization. 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 f3071f3aac5..65246da7a23 100644 --- a/clang-tools-extra/test/clang-tidy/modernize-make-unique.cpp +++ b/clang-tools-extra/test/clang-tidy/modernize-make-unique.cpp @@ -341,6 +341,9 @@ void initialization(int T, Base b) { // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: use std::make_unique instead // CHECK-FIXES: PE1 = std::make_unique<E>(); + // No warnings for `auto` new expression. + PE1.reset(new auto(E())); + //============================================================================ // NOTE: For initlializer-list constructors, the check only gives warnings, // and no fixes are generated. |