Author: madsravn Date: Sun May 26 10:00:38 2019 New Revision: 361735 URL: http://llvm.org/viewvc/llvm-project?rev=361735&view=rev Log: DeleteNullPointerCheck now deletes until the end brace of the condition.
Patch by Jonathan Camilleri Differential Revision https://reviews.llvm.org/D61861 Modified: clang-tools-extra/trunk/clang-tidy/readability/DeleteNullPointerCheck.cpp clang-tools-extra/trunk/test/clang-tidy/readability-delete-null-pointer.cpp Modified: clang-tools-extra/trunk/clang-tidy/readability/DeleteNullPointerCheck.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/readability/DeleteNullPointerCheck.cpp?rev=361735&r1=361734&r2=361735&view=diff ============================================================================== --- clang-tools-extra/trunk/clang-tidy/readability/DeleteNullPointerCheck.cpp (original) +++ clang-tools-extra/trunk/clang-tidy/readability/DeleteNullPointerCheck.cpp Sun May 26 10:00:38 2019 @@ -7,6 +7,7 @@ //===----------------------------------------------------------------------===// #include "DeleteNullPointerCheck.h" +#include "../utils/LexerUtils.h" #include "clang/AST/ASTContext.h" #include "clang/ASTMatchers/ASTMatchFinder.h" #include "clang/Lex/Lexer.h" @@ -62,9 +63,11 @@ void DeleteNullPointerCheck::check(const Diag << FixItHint::CreateRemoval(CharSourceRange::getTokenRange( IfWithDelete->getBeginLoc(), - Lexer::getLocForEndOfToken(IfWithDelete->getCond()->getEndLoc(), 0, - *Result.SourceManager, - Result.Context->getLangOpts()))); + utils::lexer::getPreviousToken(IfWithDelete->getThen()->getBeginLoc(), + *Result.SourceManager, + Result.Context->getLangOpts()) + .getLocation())); + if (Compound) { Diag << FixItHint::CreateRemoval( CharSourceRange::getTokenRange(Compound->getLBracLoc())); Modified: clang-tools-extra/trunk/test/clang-tidy/readability-delete-null-pointer.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/readability-delete-null-pointer.cpp?rev=361735&r1=361734&r2=361735&view=diff ============================================================================== --- clang-tools-extra/trunk/test/clang-tidy/readability-delete-null-pointer.cpp (original) +++ clang-tools-extra/trunk/test/clang-tidy/readability-delete-null-pointer.cpp Sun May 26 10:00:38 2019 @@ -3,6 +3,15 @@ #define NULL 0 void f() { + int *ps = 0; + if (ps /**/) // #0 + delete ps; + // CHECK-MESSAGES: :[[@LINE-2]]:3: warning: 'if' statement is unnecessary; deleting null pointer has no effect [readability-delete-null-pointer] + + // CHECK-FIXES: int *ps = 0; + // CHECK-FIXES-NEXT: {{^ }}// #0 + // CHECK-FIXES-NEXT: delete ps; + int *p = 0; // #1 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits