[PATCH] D17958: [clang-tidy] Make 'modernize-use-nullptr' check ignores NULL marcos used in other macros.

Haojian Wu via cfe-commits cfe-commits at lists.llvm.org
Fri Mar 11 03:45:14 PST 2016


This revision was automatically updated to reflect the committed changes.
Closed by commit rL263221: [clang-tidy] Make 'modernize-use-nullptr' check ignores NULL marcos used in… (authored by hokein).

Changed prior to commit:
  http://reviews.llvm.org/D17958?vs=50409&id=50414#toc

Repository:
  rL LLVM

http://reviews.llvm.org/D17958

Files:
  clang-tools-extra/trunk/clang-tidy/modernize/UseNullptrCheck.cpp
  clang-tools-extra/trunk/test/clang-tidy/modernize-use-nullptr.cpp

Index: clang-tools-extra/trunk/clang-tidy/modernize/UseNullptrCheck.cpp
===================================================================
--- clang-tools-extra/trunk/clang-tidy/modernize/UseNullptrCheck.cpp
+++ clang-tools-extra/trunk/clang-tidy/modernize/UseNullptrCheck.cpp
@@ -226,6 +226,12 @@
     if (SM.isMacroArgExpansion(StartLoc) && SM.isMacroArgExpansion(EndLoc)) {
       SourceLocation FileLocStart = SM.getFileLoc(StartLoc),
                      FileLocEnd = SM.getFileLoc(EndLoc);
+      SourceLocation ImmediateMarcoArgLoc, MacroLoc;
+      // Skip NULL macros used in macro.
+      if (!getMacroAndArgLocations(StartLoc, ImmediateMarcoArgLoc, MacroLoc) ||
+          ImmediateMarcoArgLoc != FileLocStart)
+        return skipSubTree();
+
       if (isReplaceableRange(FileLocStart, FileLocEnd, SM) &&
           allArgUsesValid(C)) {
         replaceWithNullptr(Check, SM, FileLocStart, FileLocEnd);
Index: clang-tools-extra/trunk/test/clang-tidy/modernize-use-nullptr.cpp
===================================================================
--- clang-tools-extra/trunk/test/clang-tidy/modernize-use-nullptr.cpp
+++ clang-tools-extra/trunk/test/clang-tidy/modernize-use-nullptr.cpp
@@ -195,6 +195,16 @@
   // CHECK-FIXES: assert2(p == nullptr);
 #undef assert2
 #undef assert1
+
+#define ASSERT_EQ(a, b) a == b
+#define ASSERT_NULL(x) ASSERT_EQ(static_cast<void *>(NULL), x)
+  int *pp;
+  ASSERT_NULL(pp);
+  ASSERT_NULL(NULL);
+  // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: use nullptr
+  // CHECK-FIXES: ASSERT_NULL(nullptr);
+#undef ASSERT_NULL
+#undef ASSERT_EQ
 }
 
 // One of the ancestor of the cast is a NestedNameSpecifierLoc.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D17958.50414.patch
Type: text/x-patch
Size: 1656 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160311/e9c8a239/attachment.bin>


More information about the cfe-commits mailing list