From f193bff5be04a2c9923af44668f5cf978ace74a9 Mon Sep 17 00:00:00 2001 From: Haojian Wu Date: Thu, 29 Jun 2017 08:43:36 +0000 Subject: [PATCH] [clang-tidy] Fix modernize-use-nullptr only warns the first NULL argument. Reviewers: alexfh Reviewed By: alexfh Subscribers: xazax.hun, cfe-commits Differential Revision: https://reviews.llvm.org/D34526 llvm-svn: 306651 --- .../clang-tidy/modernize/UseNullptrCheck.cpp | 2 +- .../test/clang-tidy/modernize-use-nullptr.cpp | 28 +++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/clang-tools-extra/clang-tidy/modernize/UseNullptrCheck.cpp b/clang-tools-extra/clang-tidy/modernize/UseNullptrCheck.cpp index 9de4e622585a..9c7eb04f6c13 100644 --- a/clang-tools-extra/clang-tidy/modernize/UseNullptrCheck.cpp +++ b/clang-tools-extra/clang-tidy/modernize/UseNullptrCheck.cpp @@ -235,7 +235,7 @@ public: allArgUsesValid(C)) { replaceWithNullptr(Check, SM, FileLocStart, FileLocEnd); } - return skipSubTree(); + return true; } if (SM.isMacroBodyExpansion(StartLoc) && SM.isMacroBodyExpansion(EndLoc)) { 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 45d44602dd23..878c11473c92 100644 --- a/clang-tools-extra/test/clang-tidy/modernize-use-nullptr.cpp +++ b/clang-tools-extra/test/clang-tidy/modernize-use-nullptr.cpp @@ -275,3 +275,31 @@ void test_cast_nullptr() { G(g(static_cast(nullptr))); G(g(static_cast(nullptr))); } + +// Test on recognizing multiple NULLs. +class H { +public: + H(bool); +}; + +#define T(expression) H(expression); +bool h(int *, int *, int * = nullptr); +void test_multiple_nulls() { + T(h(NULL, NULL)); +// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: use nullptr +// CHECK-MESSAGES: :[[@LINE-2]]:13: warning: use nullptr +// CHECK-FIXES: T(h(nullptr, nullptr)); + T(h(NULL, nullptr)); +// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: use nullptr +// CHECK-FIXES: T(h(nullptr, nullptr)); + T(h(nullptr, NULL)); +// CHECK-MESSAGES: :[[@LINE-1]]:16: warning: use nullptr +// CHECK-FIXES: T(h(nullptr, nullptr)); + T(h(nullptr, nullptr)); + T(h(NULL, NULL, NULL)); +// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: use nullptr +// CHECK-MESSAGES: :[[@LINE-2]]:13: warning: use nullptr +// CHECK-MESSAGES: :[[@LINE-3]]:19: warning: use nullptr +// CHECK-FIXES: T(h(nullptr, nullptr, nullptr)); +} +#undef T