https://github.com/vbvictor created https://github.com/llvm/llvm-project/pull/182844
This check tells users to use `reinterpret_cast`, which is not possible in pure C code. >From f9c549b700600acac6bc959f9097424a19fc73f8 Mon Sep 17 00:00:00 2001 From: Victor Baranov <[email protected]> Date: Mon, 23 Feb 2026 16:23:38 +0300 Subject: [PATCH 1/2] [clang-tidy] Fix bugprone-casting-through-void to run only on C++ code --- .../clang-tidy/bugprone/CastingThroughVoidCheck.h | 3 +++ .../checkers/bugprone/casting-through-void.c | 11 +++++++++++ 2 files changed, 14 insertions(+) create mode 100644 clang-tools-extra/test/clang-tidy/checkers/bugprone/casting-through-void.c diff --git a/clang-tools-extra/clang-tidy/bugprone/CastingThroughVoidCheck.h b/clang-tools-extra/clang-tidy/bugprone/CastingThroughVoidCheck.h index 0d2eba1977e97..1556e6d1b82d5 100644 --- a/clang-tools-extra/clang-tidy/bugprone/CastingThroughVoidCheck.h +++ b/clang-tools-extra/clang-tidy/bugprone/CastingThroughVoidCheck.h @@ -22,6 +22,9 @@ class CastingThroughVoidCheck : public ClangTidyCheck { : ClangTidyCheck(Name, Context) {} void registerMatchers(ast_matchers::MatchFinder *Finder) override; void check(const ast_matchers::MatchFinder::MatchResult &Result) override; + bool isLanguageVersionSupported(const LangOptions &LangOpts) const override { + return LangOpts.CPlusPlus; + } std::optional<TraversalKind> getCheckTraversalKind() const override { return TK_IgnoreUnlessSpelledInSource; } diff --git a/clang-tools-extra/test/clang-tidy/checkers/bugprone/casting-through-void.c b/clang-tools-extra/test/clang-tidy/checkers/bugprone/casting-through-void.c new file mode 100644 index 0000000000000..28d5dfb7d229b --- /dev/null +++ b/clang-tools-extra/test/clang-tidy/checkers/bugprone/casting-through-void.c @@ -0,0 +1,11 @@ +// RUN: clang-tidy -checks='-*,bugprone-casting-through-void' %s -- -std=c99 2>&1 | FileCheck %s --allow-empty +// CHECK-NOT: warning: + +double d = 100; + +void normal_test() { + (int *)(void *)&d; + int x = 1; + char *y = (char*)(void*)&x; + char *z = (char*)&x; +} >From c4c2dec47202a3551883dd772446b8f9e70cd19c Mon Sep 17 00:00:00 2001 From: Victor Baranov <[email protected]> Date: Mon, 23 Feb 2026 16:26:44 +0300 Subject: [PATCH 2/2] add release notes --- clang-tools-extra/docs/ReleaseNotes.rst | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst index 2bb4800df47c9..4f4e49a35fe4c 100644 --- a/clang-tools-extra/docs/ReleaseNotes.rst +++ b/clang-tools-extra/docs/ReleaseNotes.rst @@ -153,6 +153,10 @@ Changes in existing checks <clang-tidy/checks/bugprone/bad-signal-to-kill-thread>` check by fixing false negatives when the ``SIGTERM`` macro is obtained from a precompiled header. +- Improved :doc:`bugprone-casting-through-void + <clang-tidy/checks/bugprone/casting-through-void>` check by running only on + C++ files because suggested ``reinterpret_cast`` is not available in pure C. + - Improved :doc:`bugprone-exception-escape <clang-tidy/checks/bugprone/exception-escape>` check by adding `TreatFunctionsWithoutSpecificationAsThrowing` option to support reporting _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
