[clang-tidy] No warning for auto new expression in smart check
authorHaojian Wu <hokein@google.com>
Mon, 26 Nov 2018 12:42:08 +0000 (12:42 +0000)
committerHaojian Wu <hokein@google.com>
Mon, 26 Nov 2018 12:42:08 +0000 (12:42 +0000)
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

clang-tools-extra/clang-tidy/modernize/MakeSmartPtrCheck.cpp
clang-tools-extra/test/clang-tidy/modernize-make-unique.cpp

index c8d66ca..15b88b8 100644 (file)
@@ -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.
index f3071f3..65246da 100644 (file)
@@ -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.