[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 02:54:24 PST 2016
hokein updated this revision to Diff 50409.
hokein added a comment.
Format code.
http://reviews.llvm.org/D17958
Files:
clang-tidy/modernize/UseNullptrCheck.cpp
test/clang-tidy/modernize-use-nullptr.cpp
Index: test/clang-tidy/modernize-use-nullptr.cpp
===================================================================
--- test/clang-tidy/modernize-use-nullptr.cpp
+++ 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.
Index: clang-tidy/modernize/UseNullptrCheck.cpp
===================================================================
--- clang-tidy/modernize/UseNullptrCheck.cpp
+++ 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);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D17958.50409.patch
Type: text/x-patch
Size: 1512 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160311/7b09ac5f/attachment.bin>
More information about the cfe-commits
mailing list