[clang-tools-extra] r263221 - [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:40:09 PST 2016
Author: hokein
Date: Fri Mar 11 05:40:08 2016
New Revision: 263221
URL: http://llvm.org/viewvc/llvm-project?rev=263221&view=rev
Log:
[clang-tidy] Make 'modernize-use-nullptr' check ignores NULL marcos used in other macros.
Reviewers: bkramer, alexfh
Subscribers: cfe-commits
Differential Revision: http://reviews.llvm.org/D17958
Modified:
clang-tools-extra/trunk/clang-tidy/modernize/UseNullptrCheck.cpp
clang-tools-extra/trunk/test/clang-tidy/modernize-use-nullptr.cpp
Modified: clang-tools-extra/trunk/clang-tidy/modernize/UseNullptrCheck.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/modernize/UseNullptrCheck.cpp?rev=263221&r1=263220&r2=263221&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/modernize/UseNullptrCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/modernize/UseNullptrCheck.cpp Fri Mar 11 05:40:08 2016
@@ -226,6 +226,12 @@ public:
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);
Modified: clang-tools-extra/trunk/test/clang-tidy/modernize-use-nullptr.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/modernize-use-nullptr.cpp?rev=263221&r1=263220&r2=263221&view=diff
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/modernize-use-nullptr.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/modernize-use-nullptr.cpp Fri Mar 11 05:40:08 2016
@@ -195,6 +195,16 @@ void test_macro_args() {
// 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.
More information about the cfe-commits
mailing list