https://github.com/SonareMradul updated https://github.com/llvm/llvm-project/pull/173159
>From c44ca1e6ac8f2fa11abf44de0d9ad7afabaddaab Mon Sep 17 00:00:00 2001 From: "[email protected]" <[email protected]> Date: Sat, 20 Dec 2025 17:31:59 +0000 Subject: [PATCH 1/3] [clang-tidy] Add fix-it for C-style cast of nullptr --- .../clang-tidy/modernize/AvoidCStyleCastCheck.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/clang-tools-extra/clang-tidy/modernize/AvoidCStyleCastCheck.cpp b/clang-tools-extra/clang-tidy/modernize/AvoidCStyleCastCheck.cpp index 76f2030158c81..2e7fc0f364b48 100644 --- a/clang-tools-extra/clang-tidy/modernize/AvoidCStyleCastCheck.cpp +++ b/clang-tools-extra/clang-tidy/modernize/AvoidCStyleCastCheck.cpp @@ -218,6 +218,11 @@ void AvoidCStyleCastCheck::check(const MatchFinder::MatchResult &Result) { ReplaceWithNamedCast("static_cast"); return; case CK_NoOp: + if (isa<CXXNullPtrLiteralExpr>(CastExpr->getSubExprAsWritten()->IgnoreImpCasts())) { + ReplaceWithNamedCast("static_cast"); + return; +} + if (FnToFnCast) { ReplaceWithNamedCast("static_cast"); return; >From 0715c6c726b0c447194ae9b7c76720fe753562c9 Mon Sep 17 00:00:00 2001 From: "[email protected]" <[email protected]> Date: Sun, 21 Dec 2025 07:24:47 +0000 Subject: [PATCH 2/3] [clang-tidy] Add test and release note for nullptr cast fix. --- clang-tools-extra/docs/ReleaseNotes.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst index 924b2c03cfd18..492d31e09314f 100644 --- a/clang-tools-extra/docs/ReleaseNotes.rst +++ b/clang-tools-extra/docs/ReleaseNotes.rst @@ -543,7 +543,8 @@ Changes in existing checks <clang-tidy/checks/modernize/use-nullptr>` check by fixing a crash on Windows when the check was enabled with a 32-bit :program:`clang-tidy` binary. - +- Fixed google-readability-casting to provide a fix-it for C-style casts of + nullptr. - Improved :doc:`modernize-use-override <clang-tidy/checks/modernize/use-override>` by fixing an issue where the check would sometimes suggest inserting ``override`` in an invalid >From e66f78558e9dec353712a9351e2d8360eb0cc4ed Mon Sep 17 00:00:00 2001 From: "[email protected]" <[email protected]> Date: Sun, 21 Dec 2025 07:27:19 +0000 Subject: [PATCH 3/3] [clang-tidy] Add test and release note for nullptr cast fix --- .../clang-tidy/checkers/modernize/avoid-c-style-cast.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/clang-tools-extra/test/clang-tidy/checkers/modernize/avoid-c-style-cast.cpp b/clang-tools-extra/test/clang-tidy/checkers/modernize/avoid-c-style-cast.cpp index 52b4d471bda9b..9564833a8789a 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/modernize/avoid-c-style-cast.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/modernize/avoid-c-style-cast.cpp @@ -368,3 +368,12 @@ void functional_casts() { throw S2(5.0f); } +void f(int *); +void f(double *); + +void test_nullptr_cast() { + f((int*)nullptr); +} +// CHECK-MESSAGES: warning: C-style casts are discouraged +// CHECK-FIXES: f(static_cast<int*>(nullptr)); + _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
