[clang-tools-extra] [clang-tidy] Rename google-readability-casting to modernize-avoid-c-style-cast (PR #171058)
Islam Imad via cfe-commits
cfe-commits at lists.llvm.org
Mon Dec 8 07:50:16 PST 2025
https://github.com/Islam-Imad updated https://github.com/llvm/llvm-project/pull/171058
>From b0e4d736d9085f0db54a9267883ce7fdbd118ce6 Mon Sep 17 00:00:00 2001
From: Islam-Imad <islamimad404 at gmail.com>
Date: Sun, 7 Dec 2025 23:28:22 +0200
Subject: [PATCH 1/6] [clang-tidy] Rename google-readability-casting to
modernize-avoid-c-style-cast The old name is kept as an alias for backward
compatibility.
Fixes #170978
---
.../clang-tidy/google/CMakeLists.txt | 1 -
.../clang-tidy/google/GoogleTidyModule.cpp | 4 ++--
.../AvoidCStyleCastsCheck.cpp | 4 ++--
.../AvoidCStyleCastsCheck.h | 12 +++++-----
.../clang-tidy/modernize/CMakeLists.txt | 1 +
.../modernize/ModernizeTidyModule.cpp | 3 +++
clang-tools-extra/docs/ReleaseNotes.rst | 5 ++++
.../checks/google/readability-casting.rst | 10 +-------
.../docs/clang-tidy/checks/list.rst | 3 ++-
.../checks/modernize/avoid-c-style-cast.rst | 14 +++++++++++
.../checkers/google/readability-casting.c | 24 -------------------
.../checkers/modernize/avoid-c-style-cast.c | 24 +++++++++++++++++++
.../avoid-c-style-cast.cpp} | 8 +++----
.../infrastructure/nolintbeginend-LIFO.cpp | 6 ++---
...lintbeginend-begin-multiple-end-single.cpp | 6 ++---
...lintbeginend-begin-single-end-multiple.cpp | 6 ++---
.../nolintbeginend-mismatched-check-names.cpp | 4 ++--
17 files changed, 75 insertions(+), 60 deletions(-)
rename clang-tools-extra/clang-tidy/{google => modernize}/AvoidCStyleCastsCheck.cpp (99%)
rename clang-tools-extra/clang-tidy/{google => modernize}/AvoidCStyleCastsCheck.h (76%)
create mode 100644 clang-tools-extra/docs/clang-tidy/checks/modernize/avoid-c-style-cast.rst
delete mode 100644 clang-tools-extra/test/clang-tidy/checkers/google/readability-casting.c
create mode 100644 clang-tools-extra/test/clang-tidy/checkers/modernize/avoid-c-style-cast.c
rename clang-tools-extra/test/clang-tidy/checkers/{google/readability-casting.cpp => modernize/avoid-c-style-cast.cpp} (98%)
diff --git a/clang-tools-extra/clang-tidy/google/CMakeLists.txt b/clang-tools-extra/clang-tidy/google/CMakeLists.txt
index 1d4229ebb7b09..ac053bc92a0a4 100644
--- a/clang-tools-extra/clang-tidy/google/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/google/CMakeLists.txt
@@ -4,7 +4,6 @@ set(LLVM_LINK_COMPONENTS
)
add_clang_library(clangTidyGoogleModule STATIC
- AvoidCStyleCastsCheck.cpp
AvoidNSObjectNewCheck.cpp
AvoidThrowingObjCExceptionCheck.cpp
AvoidUnderscoreInGoogletestNameCheck.cpp
diff --git a/clang-tools-extra/clang-tidy/google/GoogleTidyModule.cpp b/clang-tools-extra/clang-tidy/google/GoogleTidyModule.cpp
index aff8b45ff2f74..7080280b4e7bd 100644
--- a/clang-tools-extra/clang-tidy/google/GoogleTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/google/GoogleTidyModule.cpp
@@ -9,10 +9,10 @@
#include "../ClangTidy.h"
#include "../ClangTidyModule.h"
#include "../ClangTidyModuleRegistry.h"
+#include "../modernize/AvoidCStyleCastsCheck.h"
#include "../readability/BracesAroundStatementsCheck.h"
#include "../readability/FunctionSizeCheck.h"
#include "../readability/NamespaceCommentCheck.h"
-#include "AvoidCStyleCastsCheck.h"
#include "AvoidNSObjectNewCheck.h"
#include "AvoidThrowingObjCExceptionCheck.h"
#include "AvoidUnderscoreInGoogletestNameCheck.h"
@@ -67,7 +67,7 @@ class GoogleModule : public ClangTidyModule {
CheckFactories
.registerCheck<readability::AvoidUnderscoreInGoogletestNameCheck>(
"google-readability-avoid-underscore-in-googletest-name");
- CheckFactories.registerCheck<readability::AvoidCStyleCastsCheck>(
+ CheckFactories.registerCheck<modernize::AvoidCStyleCastsCheck>(
"google-readability-casting");
CheckFactories.registerCheck<readability::TodoCommentCheck>(
"google-readability-todo");
diff --git a/clang-tools-extra/clang-tidy/google/AvoidCStyleCastsCheck.cpp b/clang-tools-extra/clang-tidy/modernize/AvoidCStyleCastsCheck.cpp
similarity index 99%
rename from clang-tools-extra/clang-tidy/google/AvoidCStyleCastsCheck.cpp
rename to clang-tools-extra/clang-tidy/modernize/AvoidCStyleCastsCheck.cpp
index c438889e22ab7..d76f9d0b74007 100644
--- a/clang-tools-extra/clang-tidy/google/AvoidCStyleCastsCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/AvoidCStyleCastsCheck.cpp
@@ -14,7 +14,7 @@
using namespace clang::ast_matchers;
-namespace clang::tidy::google::readability {
+namespace clang::tidy::modernize {
void AvoidCStyleCastsCheck::registerMatchers(
ast_matchers::MatchFinder *Finder) {
@@ -288,4 +288,4 @@ void AvoidCStyleCastsCheck::check(const MatchFinder::MatchResult &Result) {
Diag << "static_cast/const_cast/reinterpret_cast";
}
-} // namespace clang::tidy::google::readability
+} // namespace clang::tidy::modernize
diff --git a/clang-tools-extra/clang-tidy/google/AvoidCStyleCastsCheck.h b/clang-tools-extra/clang-tidy/modernize/AvoidCStyleCastsCheck.h
similarity index 76%
rename from clang-tools-extra/clang-tidy/google/AvoidCStyleCastsCheck.h
rename to clang-tools-extra/clang-tidy/modernize/AvoidCStyleCastsCheck.h
index a305bd524aefb..920596e260348 100644
--- a/clang-tools-extra/clang-tidy/google/AvoidCStyleCastsCheck.h
+++ b/clang-tools-extra/clang-tidy/modernize/AvoidCStyleCastsCheck.h
@@ -6,12 +6,12 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_GOOGLE_AVOIDCSTYLECASTSCHECK_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_GOOGLE_AVOIDCSTYLECASTSCHECK_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_AVOIDCSTYLECASTSCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_AVOIDCSTYLECASTSCHECK_H
#include "../ClangTidyCheck.h"
-namespace clang::tidy::google::readability {
+namespace clang::tidy::modernize {
/// Finds usages of C-style casts.
///
@@ -24,7 +24,7 @@ namespace clang::tidy::google::readability {
/// ones generated by `-Wold-style-cast`.
///
/// For the user-facing documentation see:
-/// https://clang.llvm.org/extra/clang-tidy/checks/google/readability-casting.html
+/// https://clang.llvm.org/extra/clang-tidy/checks/modernize/avoid-c-style-cast.html
class AvoidCStyleCastsCheck : public ClangTidyCheck {
public:
AvoidCStyleCastsCheck(StringRef Name, ClangTidyContext *Context)
@@ -36,6 +36,6 @@ class AvoidCStyleCastsCheck : public ClangTidyCheck {
}
};
-} // namespace clang::tidy::google::readability
+} // namespace clang::tidy::modernize
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_GOOGLE_AVOIDCSTYLECASTSCHECK_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_AVOIDCSTYLECASTSCHECK_H
diff --git a/clang-tools-extra/clang-tidy/modernize/CMakeLists.txt b/clang-tools-extra/clang-tidy/modernize/CMakeLists.txt
index 882f2dc9fb4d8..ac26c3d9bec6f 100644
--- a/clang-tools-extra/clang-tidy/modernize/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/modernize/CMakeLists.txt
@@ -6,6 +6,7 @@ set(LLVM_LINK_COMPONENTS
add_clang_library(clangTidyModernizeModule STATIC
AvoidBindCheck.cpp
AvoidCArraysCheck.cpp
+ AvoidCStyleCastsCheck.cpp
AvoidSetjmpLongjmpCheck.cpp
AvoidVariadicFunctionsCheck.cpp
ConcatNestedNamespacesCheck.cpp
diff --git a/clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp b/clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp
index 360e2b8434d0c..793dd3d025e21 100644
--- a/clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp
@@ -11,6 +11,7 @@
#include "../ClangTidyModuleRegistry.h"
#include "AvoidBindCheck.h"
#include "AvoidCArraysCheck.h"
+#include "AvoidCStyleCastsCheck.h"
#include "AvoidSetjmpLongjmpCheck.h"
#include "AvoidVariadicFunctionsCheck.h"
#include "ConcatNestedNamespacesCheck.h"
@@ -65,6 +66,8 @@ class ModernizeModule : public ClangTidyModule {
void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override {
CheckFactories.registerCheck<AvoidBindCheck>("modernize-avoid-bind");
CheckFactories.registerCheck<AvoidCArraysCheck>("modernize-avoid-c-arrays");
+ CheckFactories.registerCheck<AvoidCStyleCastsCheck>(
+ "modernize-avoid-c-style-cast");
CheckFactories.registerCheck<AvoidSetjmpLongjmpCheck>(
"modernize-avoid-setjmp-longjmp");
CheckFactories.registerCheck<AvoidVariadicFunctionsCheck>(
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst
index 42160fa9cb51c..322ce8e9d39ea 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -328,6 +328,11 @@ New check aliases
<clang-tidy/checks/bugprone/copy-constructor-mutates-argument>`
keeping initial check as an alias to the new one.
+- Renamed :doc:`google-readability-casting <clang-tidy/checks/google/readability-casting>` to
+ :doc:`modernize-avoid-c-style-cast
+ <clang-tidy/checks/modernize/avoid-c-style-cast>`
+ keeping initial check as an alias to the new one.
+
Changes in existing checks
^^^^^^^^^^^^^^^^^^^^^^^^^^
diff --git a/clang-tools-extra/docs/clang-tidy/checks/google/readability-casting.rst b/clang-tools-extra/docs/clang-tidy/checks/google/readability-casting.rst
index d927e1ce29fce..1d0c24cf375e7 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/google/readability-casting.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/google/readability-casting.rst
@@ -3,12 +3,4 @@
google-readability-casting
==========================
-Finds usages of C-style casts.
-
-https://google.github.io/styleguide/cppguide.html#Casting
-
-Corresponding cpplint.py check name: `readability/casting`.
-
-This check is similar to ``-Wold-style-cast``, but it suggests automated fixes
-in some cases. The reported locations should not be different from the
-ones generated by ``-Wold-style-cast``.
+The `google-readability-casting` check is an alias, please see `modernize-avoid-c-style-cast <../modernize/avoid-c-style-cast.html>`_ for more information.
diff --git a/clang-tools-extra/docs/clang-tidy/checks/list.rst b/clang-tools-extra/docs/clang-tidy/checks/list.rst
index 8bb112f3d1832..865a2d34e94c2 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/list.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/list.rst
@@ -239,7 +239,6 @@ Clang-Tidy Checks
:doc:`google-objc-function-naming <google/objc-function-naming>`,
:doc:`google-objc-global-variable-declaration <google/objc-global-variable-declaration>`,
:doc:`google-readability-avoid-underscore-in-googletest-name <google/readability-avoid-underscore-in-googletest-name>`,
- :doc:`google-readability-casting <google/readability-casting>`,
:doc:`google-readability-todo <google/readability-todo>`,
:doc:`google-runtime-float <google/runtime-float>`,
:doc:`google-runtime-int <google/runtime-int>`,
@@ -291,6 +290,7 @@ Clang-Tidy Checks
:doc:`misc-use-internal-linkage <misc/use-internal-linkage>`, "Yes"
:doc:`modernize-avoid-bind <modernize/avoid-bind>`, "Yes"
:doc:`modernize-avoid-c-arrays <modernize/avoid-c-arrays>`,
+ :doc:`modernize-avoid-c-style-cast <modernize/avoid-c-style-cast>`,
:doc:`modernize-avoid-setjmp-longjmp <modernize/avoid-setjmp-longjmp>`,
:doc:`modernize-avoid-variadic-functions <modernize/avoid-variadic-functions>`,
:doc:`modernize-concat-nested-namespaces <modernize/concat-nested-namespaces>`, "Yes"
@@ -585,6 +585,7 @@ Check aliases
:doc:`cppcoreguidelines-use-default-member-init <cppcoreguidelines/use-default-member-init>`, :doc:`modernize-use-default-member-init <modernize/use-default-member-init>`, "Yes"
:doc:`fuchsia-header-anon-namespaces <fuchsia/header-anon-namespaces>`, :doc:`google-build-namespaces <google/build-namespaces>`,
:doc:`google-readability-braces-around-statements <google/readability-braces-around-statements>`, :doc:`readability-braces-around-statements <readability/braces-around-statements>`, "Yes"
+ :doc:`google-readability-casting <google/readability-casting>`, :doc:`modernize-avoid-c-style-cast <modernize/avoid-c-style-cast>`,
:doc:`google-readability-function-size <google/readability-function-size>`, :doc:`readability-function-size <readability/function-size>`,
:doc:`google-readability-namespace-comments <google/readability-namespace-comments>`, :doc:`llvm-namespace-comment <llvm/namespace-comment>`,
:doc:`hicpp-avoid-c-arrays <hicpp/avoid-c-arrays>`, :doc:`modernize-avoid-c-arrays <modernize/avoid-c-arrays>`,
diff --git a/clang-tools-extra/docs/clang-tidy/checks/modernize/avoid-c-style-cast.rst b/clang-tools-extra/docs/clang-tidy/checks/modernize/avoid-c-style-cast.rst
new file mode 100644
index 0000000000000..def559a01c907
--- /dev/null
+++ b/clang-tools-extra/docs/clang-tidy/checks/modernize/avoid-c-style-cast.rst
@@ -0,0 +1,14 @@
+.. title:: clang-tidy - modernize-avoid-c-style-cast
+
+modernize-avoid-c-style-cast
+==========================
+
+Finds usages of C-style casts.
+
+https://google.github.io/styleguide/cppguide.html#Casting
+
+Corresponding cpplint.py check name: `readability/casting`.
+
+This check is similar to ``-Wold-style-cast``, but it suggests automated fixes
+in some cases. The reported locations should not be different from the
+ones generated by ``-Wold-style-cast``.
diff --git a/clang-tools-extra/test/clang-tidy/checkers/google/readability-casting.c b/clang-tools-extra/test/clang-tidy/checkers/google/readability-casting.c
deleted file mode 100644
index f0d53395576a6..0000000000000
--- a/clang-tools-extra/test/clang-tidy/checkers/google/readability-casting.c
+++ /dev/null
@@ -1,24 +0,0 @@
-// RUN: %check_clang_tidy %s google-readability-casting %t -- -- -x c
-// The testing script always adds .cpp extension to the input file name, so we
-// need to run clang-tidy directly in order to verify handling of .c files:
-// RUN: clang-tidy --checks=-*,google-readability-casting %s -- -x c++ | FileCheck %s -check-prefix=CHECK-MESSAGES -implicit-check-not='{{warning|error}}:'
-// RUN: cp %s %t.main_file.cpp
-// RUN: clang-tidy --checks=-*,google-readability-casting -header-filter='.*' %t.main_file.cpp -- -I%S -DTEST_INCLUDE -x c++ | FileCheck %s -check-prefix=CHECK-MESSAGES -implicit-check-not='{{warning|error}}:'
-
-#ifdef TEST_INCLUDE
-
-#undef TEST_INCLUDE
-#include "readability-casting.c"
-
-#else
-
-void f(const char *cpc) {
- const char *cpc2 = (const char*)cpc;
- // CHECK-MESSAGES: :[[@LINE-1]]:22: warning: redundant cast to the same type [google-readability-casting]
- // CHECK-FIXES: const char *cpc2 = cpc;
- char *pc = (char*)cpc;
- typedef const char *Typedef1;
- (Typedef1)cpc;
-}
-
-#endif
diff --git a/clang-tools-extra/test/clang-tidy/checkers/modernize/avoid-c-style-cast.c b/clang-tools-extra/test/clang-tidy/checkers/modernize/avoid-c-style-cast.c
new file mode 100644
index 0000000000000..7dfdc7be7560e
--- /dev/null
+++ b/clang-tools-extra/test/clang-tidy/checkers/modernize/avoid-c-style-cast.c
@@ -0,0 +1,24 @@
+// RUN: %check_clang_tidy %s modernize-avoid-c-style-cast %t -- -- -x c
+// The testing script always adds .cpp extension to the input file name, so we
+// need to run clang-tidy directly in order to verify handling of .c files:
+// RUN: clang-tidy --checks=-*,modernize-avoid-c-style-cast %s -- -x c++ | FileCheck %s -check-prefix=CHECK-MESSAGES -implicit-check-not='{{warning|error}}:'
+// RUN: cp %s %t.main_file.cpp
+// RUN: clang-tidy --checks=-*,modernize-avoid-c-style-cast -header-filter='.*' %t.main_file.cpp -- -I%S -DTEST_INCLUDE -x c++ | FileCheck %s -check-prefix=CHECK-MESSAGES -implicit-check-not='{{warning|error}}:'
+
+#ifdef TEST_INCLUDE
+
+#undef TEST_INCLUDE
+#include "avoid-c-style-cast.c"
+
+#else
+
+void f(const char *cpc) {
+ const char *cpc2 = (const char*)cpc;
+ // CHECK-MESSAGES: :[[@LINE-1]]:22: warning: redundant cast to the same type [modernize-avoid-c-style-cast]
+ // CHECK-FIXES: const char *cpc2 = cpc;
+ char *pc = (char*)cpc;
+ typedef const char *Typedef1;
+ (Typedef1)cpc;
+}
+
+#endif
diff --git a/clang-tools-extra/test/clang-tidy/checkers/google/readability-casting.cpp b/clang-tools-extra/test/clang-tidy/checkers/modernize/avoid-c-style-cast.cpp
similarity index 98%
rename from clang-tools-extra/test/clang-tidy/checkers/google/readability-casting.cpp
rename to clang-tools-extra/test/clang-tidy/checkers/modernize/avoid-c-style-cast.cpp
index d8e8c5017a9b2..52b4d471bda9b 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/google/readability-casting.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/modernize/avoid-c-style-cast.cpp
@@ -1,4 +1,4 @@
-// RUN: %check_clang_tidy -std=c++11-or-later %s google-readability-casting %t -- -- -fexceptions
+// RUN: %check_clang_tidy -std=c++11-or-later %s modernize-avoid-c-style-cast %t -- -- -fexceptions
bool g() { return false; }
@@ -8,14 +8,14 @@ struct Y : public X {};
void f(int a, double b, const char *cpc, const void *cpv, X *pX) {
const char *cpc2 = (const char*)cpc;
- // CHECK-MESSAGES: :[[@LINE-1]]:22: warning: redundant cast to the same type [google-readability-casting]
+ // CHECK-MESSAGES: :[[@LINE-1]]:22: warning: redundant cast to the same type [modernize-avoid-c-style-cast]
// CHECK-FIXES: const char *cpc2 = cpc;
typedef const char *Typedef1;
typedef const char *Typedef2;
Typedef1 t1;
(Typedef2)t1;
- // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: C-style casts are discouraged; use static_cast (if needed, the cast may be redundant) [google-readability-casting]
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: C-style casts are discouraged; use static_cast (if needed, the cast may be redundant) [modernize-avoid-c-style-cast]
// CHECK-FIXES: static_cast<Typedef2>(t1);
(const char*)t1;
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: {{.*}}; use static_cast (if needed
@@ -28,7 +28,7 @@ void f(int a, double b, const char *cpc, const void *cpv, X *pX) {
// CHECK-FIXES: t1;
char *pc = (char*)cpc;
- // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: C-style casts are discouraged; use const_cast [google-readability-casting]
+ // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: C-style casts are discouraged; use const_cast [modernize-avoid-c-style-cast]
// CHECK-FIXES: char *pc = const_cast<char*>(cpc);
typedef char Char;
Char *pChar = (Char*)pc;
diff --git a/clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-LIFO.cpp b/clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-LIFO.cpp
index ee5b1cca755ab..e86b3df34fcfc 100644
--- a/clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-LIFO.cpp
+++ b/clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-LIFO.cpp
@@ -1,11 +1,11 @@
-// RUN: not clang-tidy %s --checks='-*,google-explicit-constructor,google-readability-casting' 2>&1 | FileCheck %s
+// RUN: not clang-tidy %s --checks='-*,google-explicit-constructor,modernize-avoid-c-style-cast' 2>&1 | FileCheck %s
// NOLINTBEGIN(google-explicit-constructor)
-// NOLINTBEGIN(google-readability-casting)
+// NOLINTBEGIN(modernize-avoid-c-style-cast)
class A { A(int i); };
auto Num = (unsigned int)(-1);
// NOLINTEND(google-explicit-constructor)
-// NOLINTEND(google-readability-casting)
+// NOLINTEND(modernize-avoid-c-style-cast)
// Note: the expected output has been split over several lines so that clang-tidy
// does not see the "no lint" suppression comment and mistakenly assume it
diff --git a/clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-begin-multiple-end-single.cpp b/clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-begin-multiple-end-single.cpp
index 150913ce0ec69..156a5cb345dbd 100644
--- a/clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-begin-multiple-end-single.cpp
+++ b/clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-begin-multiple-end-single.cpp
@@ -1,10 +1,10 @@
-// RUN: not clang-tidy %s --checks='-*,google-explicit-constructor,google-readability-casting' 2>&1 | FileCheck %s
+// RUN: not clang-tidy %s --checks='-*,google-explicit-constructor,modernize-avoid-c-style-cast' 2>&1 | FileCheck %s
-// NOLINTBEGIN(google-explicit-constructor,google-readability-casting)
+// NOLINTBEGIN(google-explicit-constructor,modernize-avoid-c-style-cast)
class B { B(int i); };
// NOLINTEND(google-explicit-constructor)
auto Num2 = (unsigned int)(-1);
-// NOLINTEND(google-readability-casting)
+// NOLINTEND(modernize-avoid-c-style-cast)
// Note: the expected output has been split over several lines so that clang-tidy
// does not see the "no lint" suppression comment and mistakenly assume it
diff --git a/clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-begin-single-end-multiple.cpp b/clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-begin-single-end-multiple.cpp
index f9a915c890cbb..837213227dc2d 100644
--- a/clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-begin-single-end-multiple.cpp
+++ b/clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-begin-single-end-multiple.cpp
@@ -1,10 +1,10 @@
-// RUN: not clang-tidy %s --checks='-*,google-explicit-constructor,google-readability-casting' 2>&1 | FileCheck %s
+// RUN: not clang-tidy %s --checks='-*,google-explicit-constructor,modernize-avoid-c-style-cast' 2>&1 | FileCheck %s
// NOLINTBEGIN(google-explicit-constructor)
-// NOLINTBEGIN(google-readability-casting)
+// NOLINTBEGIN(modernize-avoid-c-style-cast)
class B { B(int i); };
auto Num2 = (unsigned int)(-1);
-// NOLINTEND(google-explicit-constructor,google-readability-casting)
+// NOLINTEND(google-explicit-constructor,modernize-avoid-c-style-cast)
// Note: the expected output has been split over several lines so that clang-tidy
// does not see the "no lint" suppression comment and mistakenly assume it
diff --git a/clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-mismatched-check-names.cpp b/clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-mismatched-check-names.cpp
index 8d7786fb8c712..ddd399dfc764f 100644
--- a/clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-mismatched-check-names.cpp
+++ b/clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-mismatched-check-names.cpp
@@ -1,9 +1,9 @@
-// RUN: not clang-tidy %s --checks='-*,google-explicit-constructor,google-readability-casting' 2>&1 | FileCheck %s
+// RUN: not clang-tidy %s --checks='-*,google-explicit-constructor,modernize-avoid-c-style-cast' 2>&1 | FileCheck %s
// NOLINTBEGIN(google-explicit-constructor)
class A { A(int i); };
auto Num = (unsigned int)(-1);
-// NOLINTEND(google-readability-casting)
+// NOLINTEND(modernize-avoid-c-style-cast)
// Note: the expected output has been split over several lines so that clang-tidy
// does not see the "no lint" suppression comment and mistakenly assume it
>From 2b6af309670b0e0a6b7284e859ffe62b67bb2ec8 Mon Sep 17 00:00:00 2001
From: Islam-Imad <islamimad404 at gmail.com>
Date: Sun, 7 Dec 2025 23:39:30 +0200
Subject: [PATCH 2/6] [docs] Fix RST title underline length
---
.../docs/clang-tidy/checks/modernize/avoid-c-style-cast.rst | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/clang-tools-extra/docs/clang-tidy/checks/modernize/avoid-c-style-cast.rst b/clang-tools-extra/docs/clang-tidy/checks/modernize/avoid-c-style-cast.rst
index def559a01c907..a9714490cbedc 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/modernize/avoid-c-style-cast.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/modernize/avoid-c-style-cast.rst
@@ -1,7 +1,7 @@
.. title:: clang-tidy - modernize-avoid-c-style-cast
modernize-avoid-c-style-cast
-==========================
+============================
Finds usages of C-style casts.
>From 258997ee36c5147d1152410bf7a8c145b614b1bd Mon Sep 17 00:00:00 2001
From: Islam-Imad <islamimad404 at gmail.com>
Date: Mon, 8 Dec 2025 13:29:20 +0200
Subject: [PATCH 3/6] [clang-tidy] Rename AvoidCStyleCastsCheck to
AvoidCStyleCastCheck
Make the check name consistent with other modernize checks by using
singular form. Also improve documentation with concrete examples.
---
.../clang-tidy/google/GoogleTidyModule.cpp | 2 +-
...astsCheck.cpp => AvoidCStyleCastCheck.cpp} | 2 +-
...yleCastsCheck.h => AvoidCStyleCastCheck.h} | 0
.../clang-tidy/modernize/CMakeLists.txt | 2 +-
.../modernize/ModernizeTidyModule.cpp | 2 +-
.../checks/google/readability-casting.rst | 8 ++++-
.../checks/modernize/avoid-c-style-cast.rst | 33 +++++++++++++++----
7 files changed, 38 insertions(+), 11 deletions(-)
rename clang-tools-extra/clang-tidy/modernize/{AvoidCStyleCastsCheck.cpp => AvoidCStyleCastCheck.cpp} (99%)
rename clang-tools-extra/clang-tidy/modernize/{AvoidCStyleCastsCheck.h => AvoidCStyleCastCheck.h} (100%)
diff --git a/clang-tools-extra/clang-tidy/google/GoogleTidyModule.cpp b/clang-tools-extra/clang-tidy/google/GoogleTidyModule.cpp
index 7080280b4e7bd..c7ed16c2212da 100644
--- a/clang-tools-extra/clang-tidy/google/GoogleTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/google/GoogleTidyModule.cpp
@@ -9,7 +9,7 @@
#include "../ClangTidy.h"
#include "../ClangTidyModule.h"
#include "../ClangTidyModuleRegistry.h"
-#include "../modernize/AvoidCStyleCastsCheck.h"
+#include "../modernize/AvoidCStyleCastCheck.h"
#include "../readability/BracesAroundStatementsCheck.h"
#include "../readability/FunctionSizeCheck.h"
#include "../readability/NamespaceCommentCheck.h"
diff --git a/clang-tools-extra/clang-tidy/modernize/AvoidCStyleCastsCheck.cpp b/clang-tools-extra/clang-tidy/modernize/AvoidCStyleCastCheck.cpp
similarity index 99%
rename from clang-tools-extra/clang-tidy/modernize/AvoidCStyleCastsCheck.cpp
rename to clang-tools-extra/clang-tidy/modernize/AvoidCStyleCastCheck.cpp
index d76f9d0b74007..ee403c5644f74 100644
--- a/clang-tools-extra/clang-tidy/modernize/AvoidCStyleCastsCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/AvoidCStyleCastCheck.cpp
@@ -6,7 +6,7 @@
//
//===----------------------------------------------------------------------===//
-#include "AvoidCStyleCastsCheck.h"
+#include "AvoidCStyleCastCheck.h"
#include "clang/AST/ASTContext.h"
#include "clang/ASTMatchers/ASTMatchFinder.h"
#include "clang/ASTMatchers/ASTMatchers.h"
diff --git a/clang-tools-extra/clang-tidy/modernize/AvoidCStyleCastsCheck.h b/clang-tools-extra/clang-tidy/modernize/AvoidCStyleCastCheck.h
similarity index 100%
rename from clang-tools-extra/clang-tidy/modernize/AvoidCStyleCastsCheck.h
rename to clang-tools-extra/clang-tidy/modernize/AvoidCStyleCastCheck.h
diff --git a/clang-tools-extra/clang-tidy/modernize/CMakeLists.txt b/clang-tools-extra/clang-tidy/modernize/CMakeLists.txt
index ac26c3d9bec6f..488c359661018 100644
--- a/clang-tools-extra/clang-tidy/modernize/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/modernize/CMakeLists.txt
@@ -6,7 +6,7 @@ set(LLVM_LINK_COMPONENTS
add_clang_library(clangTidyModernizeModule STATIC
AvoidBindCheck.cpp
AvoidCArraysCheck.cpp
- AvoidCStyleCastsCheck.cpp
+ AvoidCStyleCastCheck.cpp
AvoidSetjmpLongjmpCheck.cpp
AvoidVariadicFunctionsCheck.cpp
ConcatNestedNamespacesCheck.cpp
diff --git a/clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp b/clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp
index 793dd3d025e21..c4d95335a629b 100644
--- a/clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp
@@ -11,7 +11,7 @@
#include "../ClangTidyModuleRegistry.h"
#include "AvoidBindCheck.h"
#include "AvoidCArraysCheck.h"
-#include "AvoidCStyleCastsCheck.h"
+#include "AvoidCStyleCastCheck.h"
#include "AvoidSetjmpLongjmpCheck.h"
#include "AvoidVariadicFunctionsCheck.h"
#include "ConcatNestedNamespacesCheck.h"
diff --git a/clang-tools-extra/docs/clang-tidy/checks/google/readability-casting.rst b/clang-tools-extra/docs/clang-tidy/checks/google/readability-casting.rst
index 1d0c24cf375e7..ae9d6c095e41e 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/google/readability-casting.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/google/readability-casting.rst
@@ -3,4 +3,10 @@
google-readability-casting
==========================
-The `google-readability-casting` check is an alias, please see `modernize-avoid-c-style-cast <../modernize/avoid-c-style-cast.html>`_ for more information.
+The `google-readability-casting` check is an alias, please see
+:doc:`modernize-avoid-c-style-cast <../modernize/avoid-c-style-cast.html>`_
+for more information.
+
+Finds usages of C-style casts.
+
+https://google.github.io/styleguide/cppguide.html#Casting
diff --git a/clang-tools-extra/docs/clang-tidy/checks/modernize/avoid-c-style-cast.rst b/clang-tools-extra/docs/clang-tidy/checks/modernize/avoid-c-style-cast.rst
index a9714490cbedc..5bdca1b4ffe24 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/modernize/avoid-c-style-cast.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/modernize/avoid-c-style-cast.rst
@@ -3,12 +3,33 @@
modernize-avoid-c-style-cast
============================
-Finds usages of C-style casts.
+This check is similar to ``-Wold-style-cast``, but it suggests automated fixes
+in some cases. The reported locations should not be different from the ones
+generated by ``-Wold-style-cast``.
-https://google.github.io/styleguide/cppguide.html#Casting
+C-style casts can perform a variety of different conversions (``const_cast``,
+``static_cast``, ``reinterpret_cast``, or a combination). This makes them
+dangerous as the intent is not clear, and they can silently perform unsafe
+conversions between incompatible types.
-Corresponding cpplint.py check name: `readability/casting`.
-This check is similar to ``-Wold-style-cast``, but it suggests automated fixes
-in some cases. The reported locations should not be different from the
-ones generated by ``-Wold-style-cast``.
+Examples
+--------
+
+.. code-block:: c++
+
+ class A {
+ public:
+ std::string v;
+ };
+
+ A a;
+ double *num = (double*)(&a); // Compiles! Hides danger
+ // num = static_cast<double*>(&a); // Won't compile (good!)
+ num = reinterpret_cast<double*>(&a); // Compiles, danger is explicit
+
+
+References
+----------
+
+Corresponding cpplint.py check name: `readability/casting`.
\ No newline at end of file
>From 5eff8ef8f92a40f324e645da5baca6cd4fd96acf Mon Sep 17 00:00:00 2001
From: Islam-Imad <islamimad404 at gmail.com>
Date: Mon, 8 Dec 2025 14:16:59 +0200
Subject: [PATCH 4/6] - Renamed class in AvoidCStyleCastCheck.h and .cpp -
Updated header guards accordingly - Updated registrations in
ModernizeTidyModule.cpp and GoogleTidyModule.cpp - Fixed documentation link
formatting in google-readability-casting.rst
---
.../clang-tidy/google/GoogleTidyModule.cpp | 2 +-
.../clang-tidy/modernize/AvoidCStyleCastCheck.cpp | 4 ++--
.../clang-tidy/modernize/AvoidCStyleCastCheck.h | 10 +++++-----
.../clang-tidy/modernize/ModernizeTidyModule.cpp | 2 +-
.../clang-tidy/checks/google/readability-casting.rst | 2 +-
5 files changed, 10 insertions(+), 10 deletions(-)
diff --git a/clang-tools-extra/clang-tidy/google/GoogleTidyModule.cpp b/clang-tools-extra/clang-tidy/google/GoogleTidyModule.cpp
index c7ed16c2212da..ce46b3f641790 100644
--- a/clang-tools-extra/clang-tidy/google/GoogleTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/google/GoogleTidyModule.cpp
@@ -67,7 +67,7 @@ class GoogleModule : public ClangTidyModule {
CheckFactories
.registerCheck<readability::AvoidUnderscoreInGoogletestNameCheck>(
"google-readability-avoid-underscore-in-googletest-name");
- CheckFactories.registerCheck<modernize::AvoidCStyleCastsCheck>(
+ CheckFactories.registerCheck<modernize::AvoidCStyleCastCheck>(
"google-readability-casting");
CheckFactories.registerCheck<readability::TodoCommentCheck>(
"google-readability-todo");
diff --git a/clang-tools-extra/clang-tidy/modernize/AvoidCStyleCastCheck.cpp b/clang-tools-extra/clang-tidy/modernize/AvoidCStyleCastCheck.cpp
index ee403c5644f74..232ed2968130b 100644
--- a/clang-tools-extra/clang-tidy/modernize/AvoidCStyleCastCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/AvoidCStyleCastCheck.cpp
@@ -16,7 +16,7 @@ using namespace clang::ast_matchers;
namespace clang::tidy::modernize {
-void AvoidCStyleCastsCheck::registerMatchers(
+void AvoidCStyleCastCheck::registerMatchers(
ast_matchers::MatchFinder *Finder) {
Finder->addMatcher(
cStyleCastExpr(
@@ -113,7 +113,7 @@ static bool sameTypeAsWritten(QualType X, QualType Y) {
}
}
-void AvoidCStyleCastsCheck::check(const MatchFinder::MatchResult &Result) {
+void AvoidCStyleCastCheck::check(const MatchFinder::MatchResult &Result) {
const auto *CastExpr = Result.Nodes.getNodeAs<ExplicitCastExpr>("cast");
// Ignore casts in macros.
diff --git a/clang-tools-extra/clang-tidy/modernize/AvoidCStyleCastCheck.h b/clang-tools-extra/clang-tidy/modernize/AvoidCStyleCastCheck.h
index 920596e260348..123d524c6e3bf 100644
--- a/clang-tools-extra/clang-tidy/modernize/AvoidCStyleCastCheck.h
+++ b/clang-tools-extra/clang-tidy/modernize/AvoidCStyleCastCheck.h
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_AVOIDCSTYLECASTSCHECK_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_AVOIDCSTYLECASTSCHECK_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_AVOIDCSTYLECASTCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_AVOIDCSTYLECASTCHECK_H
#include "../ClangTidyCheck.h"
@@ -25,9 +25,9 @@ namespace clang::tidy::modernize {
///
/// For the user-facing documentation see:
/// https://clang.llvm.org/extra/clang-tidy/checks/modernize/avoid-c-style-cast.html
-class AvoidCStyleCastsCheck : public ClangTidyCheck {
+class AvoidCStyleCastCheck : public ClangTidyCheck {
public:
- AvoidCStyleCastsCheck(StringRef Name, ClangTidyContext *Context)
+ AvoidCStyleCastCheck(StringRef Name, ClangTidyContext *Context)
: ClangTidyCheck(Name, Context) {}
void registerMatchers(ast_matchers::MatchFinder *Finder) override;
void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
@@ -38,4 +38,4 @@ class AvoidCStyleCastsCheck : public ClangTidyCheck {
} // namespace clang::tidy::modernize
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_AVOIDCSTYLECASTSCHECK_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_AVOIDCSTYLECASTCHECK_H
diff --git a/clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp b/clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp
index c4d95335a629b..a410f8da6af50 100644
--- a/clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp
@@ -66,7 +66,7 @@ class ModernizeModule : public ClangTidyModule {
void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override {
CheckFactories.registerCheck<AvoidBindCheck>("modernize-avoid-bind");
CheckFactories.registerCheck<AvoidCArraysCheck>("modernize-avoid-c-arrays");
- CheckFactories.registerCheck<AvoidCStyleCastsCheck>(
+ CheckFactories.registerCheck<AvoidCStyleCastCheck>(
"modernize-avoid-c-style-cast");
CheckFactories.registerCheck<AvoidSetjmpLongjmpCheck>(
"modernize-avoid-setjmp-longjmp");
diff --git a/clang-tools-extra/docs/clang-tidy/checks/google/readability-casting.rst b/clang-tools-extra/docs/clang-tidy/checks/google/readability-casting.rst
index ae9d6c095e41e..5ef3554fc4d95 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/google/readability-casting.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/google/readability-casting.rst
@@ -4,7 +4,7 @@ google-readability-casting
==========================
The `google-readability-casting` check is an alias, please see
-:doc:`modernize-avoid-c-style-cast <../modernize/avoid-c-style-cast.html>`_
+:doc:`modernize-avoid-c-style-cast <../modernize/avoid-c-style-cast>`
for more information.
Finds usages of C-style casts.
>From b2dca18807b949cd70d38eeae2672608316b9e5a Mon Sep 17 00:00:00 2001
From: Islam Imad <143586474+Islam-Imad at users.noreply.github.com>
Date: Mon, 8 Dec 2025 14:38:41 +0200
Subject: [PATCH 5/6] Refactor registerMatchers function signature
update function signature to fit into one line
---
.../clang-tidy/modernize/AvoidCStyleCastCheck.cpp | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/clang-tools-extra/clang-tidy/modernize/AvoidCStyleCastCheck.cpp b/clang-tools-extra/clang-tidy/modernize/AvoidCStyleCastCheck.cpp
index 232ed2968130b..7f9bf63972486 100644
--- a/clang-tools-extra/clang-tidy/modernize/AvoidCStyleCastCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/AvoidCStyleCastCheck.cpp
@@ -16,8 +16,7 @@ using namespace clang::ast_matchers;
namespace clang::tidy::modernize {
-void AvoidCStyleCastCheck::registerMatchers(
- ast_matchers::MatchFinder *Finder) {
+void AvoidCStyleCastCheck::registerMatchers(ast_matchers::MatchFinder *Finder) {
Finder->addMatcher(
cStyleCastExpr(
// Filter out (EnumType)IntegerLiteral construct, which is generated
>From 451b8ebf20fa21d2a3f24a7b5eef7fc231dea478 Mon Sep 17 00:00:00 2001
From: Islam Imad <143586474+Islam-Imad at users.noreply.github.com>
Date: Mon, 8 Dec 2025 17:50:05 +0200
Subject: [PATCH 6/6] Fix formatting in avoid-c-style-cast documentation
---
.../docs/clang-tidy/checks/modernize/avoid-c-style-cast.rst | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/clang-tools-extra/docs/clang-tidy/checks/modernize/avoid-c-style-cast.rst b/clang-tools-extra/docs/clang-tidy/checks/modernize/avoid-c-style-cast.rst
index 5bdca1b4ffe24..9459ff4940d39 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/modernize/avoid-c-style-cast.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/modernize/avoid-c-style-cast.rst
@@ -3,9 +3,9 @@
modernize-avoid-c-style-cast
============================
-This check is similar to ``-Wold-style-cast``, but it suggests automated fixes
+This check is similar to `-Wold-style-cast`, but it suggests automated fixes
in some cases. The reported locations should not be different from the ones
-generated by ``-Wold-style-cast``.
+generated by `-Wold-style-cast`.
C-style casts can perform a variety of different conversions (``const_cast``,
``static_cast``, ``reinterpret_cast``, or a combination). This makes them
@@ -32,4 +32,4 @@ Examples
References
----------
-Corresponding cpplint.py check name: `readability/casting`.
\ No newline at end of file
+Corresponding cpplint.py check name: `readability/casting`.
More information about the cfe-commits
mailing list