From 0d5e9d3135f3f7784ca8c708699b324a644b97c7 Mon Sep 17 00:00:00 2001 From: Haojian Wu Date: Fri, 26 Feb 2016 15:34:35 +0000 Subject: [PATCH] [clang-tidy] Fix an assertion failure in `modernize-use-nullptr` check. Reviewers: alexfh Subscribers: cfe-commits Differential Revision: http://reviews.llvm.org/D17640 llvm-svn: 262024 --- clang-tools-extra/clang-tidy/modernize/UseNullptrCheck.cpp | 2 +- clang-tools-extra/test/clang-tidy/modernize-use-nullptr.cpp | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/clang-tools-extra/clang-tidy/modernize/UseNullptrCheck.cpp b/clang-tools-extra/clang-tidy/modernize/UseNullptrCheck.cpp index 99e4406..2923bd9 100644 --- a/clang-tools-extra/clang-tidy/modernize/UseNullptrCheck.cpp +++ b/clang-tools-extra/clang-tidy/modernize/UseNullptrCheck.cpp @@ -327,7 +327,7 @@ private: NullMacros.end(); } - MacroLoc = SM.getImmediateExpansionRange(ArgLoc).first; + MacroLoc = SM.getExpansionRange(ArgLoc).first; ArgLoc = Expansion.getSpellingLoc().getLocWithOffset(LocInfo.second); if (ArgLoc.isFileID()) diff --git a/clang-tools-extra/test/clang-tidy/modernize-use-nullptr.cpp b/clang-tools-extra/test/clang-tidy/modernize-use-nullptr.cpp index 6b41cfb..a21a43a 100644 --- a/clang-tools-extra/test/clang-tidy/modernize-use-nullptr.cpp +++ b/clang-tools-extra/test/clang-tidy/modernize-use-nullptr.cpp @@ -183,6 +183,18 @@ void test_macro_args() { // CHECK-MESSAGES: :[[@LINE-2]]:24: warning: use nullptr // CHECK-FIXES: a[2] = {ENTRY(nullptr), {nullptr}}; #undef ENTRY + +#define assert1(expr) (expr) ? 0 : 1 +#define assert2 assert1 + int *p; + assert2(p == 0); + // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: use nullptr + // CHECK-FIXES: assert2(p == nullptr); + assert2(p == NULL); + // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: use nullptr + // CHECK-FIXES: assert2(p == nullptr); +#undef assert2 +#undef assert1 } // One of the ancestor of the cast is a NestedNameSpecifierLoc. -- 2.7.4