[PATCH] D36264: [clang-tidy] Ignore macros in make-unique check.

Haojian Wu via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Aug 3 04:50:07 PDT 2017


hokein created this revision.
Herald added subscribers: xazax.hun, JDevlieghere.

The check doesn't fully support smart-ptr usages inside macros, which
may cause incorrect fixes, or even crashes, ignore them for now.


https://reviews.llvm.org/D36264

Files:
  clang-tidy/modernize/MakeSmartPtrCheck.cpp
  test/clang-tidy/modernize-make-unique.cpp


Index: test/clang-tidy/modernize-make-unique.cpp
===================================================================
--- test/clang-tidy/modernize-make-unique.cpp
+++ test/clang-tidy/modernize-make-unique.cpp
@@ -336,3 +336,14 @@
   // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: use std::make_unique instead
   // CHECK-FIXES: *Q = std::make_unique<int>();
 }
+
+#define DEFINE(...) __VA_ARGS__
+template<typename T>
+void g2(std::unique_ptr<Foo> *t) {
+  DEFINE(auto p = std::unique_ptr<Foo>(new Foo); t->reset(new Foo););
+}
+void macro() {
+  std::unique_ptr<Foo> *t;
+  g2<bar::Bar>(t);
+}
+#undef DEFINE
Index: clang-tidy/modernize/MakeSmartPtrCheck.cpp
===================================================================
--- clang-tidy/modernize/MakeSmartPtrCheck.cpp
+++ clang-tidy/modernize/MakeSmartPtrCheck.cpp
@@ -111,9 +111,9 @@
   if (New->getNumPlacementArgs() != 0)
     return;
 
-  if (Construct)
+  if (Construct && !Construct->getLocation().isMacroID())
     checkConstruct(SM, Construct, Type, New);
-  else if (Reset)
+  else if (Reset && !Reset->getExprLoc().isMacroID())
     checkReset(SM, Reset, New);
 }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D36264.109520.patch
Type: text/x-patch
Size: 1130 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170803/c8d8ebf2/attachment.bin>


More information about the cfe-commits mailing list