[clang-tools-extra] r347551 - [clang-tidy] No warning for auto new expression in smart check

Haojian Wu via cfe-commits cfe-commits at lists.llvm.org
Mon Nov 26 04:42:09 PST 2018


Author: hokein
Date: Mon Nov 26 04:42:08 2018
New Revision: 347551

URL: http://llvm.org/viewvc/llvm-project?rev=347551&view=rev
Log:
[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

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

Modified: clang-tools-extra/trunk/clang-tidy/modernize/MakeSmartPtrCheck.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/modernize/MakeSmartPtrCheck.cpp?rev=347551&r1=347550&r2=347551&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/modernize/MakeSmartPtrCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/modernize/MakeSmartPtrCheck.cpp Mon Nov 26 04:42:08 2018
@@ -120,6 +120,9 @@ void MakeSmartPtrCheck::check(const Matc
 
   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.

Modified: clang-tools-extra/trunk/test/clang-tidy/modernize-make-unique.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/modernize-make-unique.cpp?rev=347551&r1=347550&r2=347551&view=diff
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/modernize-make-unique.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/modernize-make-unique.cpp Mon Nov 26 04:42:08 2018
@@ -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.




More information about the cfe-commits mailing list