https://github.com/carlosgalvezp created https://github.com/llvm/llvm-project/pull/141209
It is deemed more of an annoyance than a help, since the patterns the check warns about are quite common and idiomatic in C, and there are no good alternatives. Thus, enable the check only for C++, where there are safer constructs. Fixes #140659 >From e1c3f4bdac2d5edd7dfa83473e3c7d21ba6c96cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20G=C3=A1lvez?= <carlos.gal...@zenseact.com> Date: Fri, 23 May 2025 07:45:04 +0000 Subject: [PATCH] [clang-tidy] Disable bugprone-multi-level-pointer-conversion in C code It is deemed more of an annoyance than a help, since the patterns the check warns about are quite common and idiomatic in C, and there are no good alternatives. Thus, enable the check only for C++, where there are safer constructs. Fixes #140659 --- .../bugprone/MultiLevelImplicitPointerConversionCheck.h | 3 +++ clang-tools-extra/docs/ReleaseNotes.rst | 4 ++++ .../bugprone/multi-level-implicit-pointer-conversion.rst | 9 +++++++++ 3 files changed, 16 insertions(+) diff --git a/clang-tools-extra/clang-tidy/bugprone/MultiLevelImplicitPointerConversionCheck.h b/clang-tools-extra/clang-tidy/bugprone/MultiLevelImplicitPointerConversionCheck.h index 13228145ff35f..c502f31d867d2 100644 --- a/clang-tools-extra/clang-tidy/bugprone/MultiLevelImplicitPointerConversionCheck.h +++ b/clang-tools-extra/clang-tidy/bugprone/MultiLevelImplicitPointerConversionCheck.h @@ -26,6 +26,9 @@ class MultiLevelImplicitPointerConversionCheck : public ClangTidyCheck { void registerMatchers(ast_matchers::MatchFinder *Finder) override; void check(const ast_matchers::MatchFinder::MatchResult &Result) override; std::optional<TraversalKind> getCheckTraversalKind() const override; + bool isLanguageVersionSupported(const LangOptions &LangOpts) const override { + return LangOpts.CPlusPlus; + } }; } // namespace clang::tidy::bugprone diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst index 9b29ab12e1bfa..7e76d81eed439 100644 --- a/clang-tools-extra/docs/ReleaseNotes.rst +++ b/clang-tools-extra/docs/ReleaseNotes.rst @@ -148,6 +148,10 @@ New check aliases Changes in existing checks ^^^^^^^^^^^^^^^^^^^^^^^^^^ +- Disabled :doc:`bugprone-multi-level-implicit-pointer-conversion + <clang-tidy/checks/bugprone/multi-level-implicit-pointer-conversion>` check in + C code. The check is now only active in C++ code. + - Improved :doc:`bugprone-optional-value-conversion <clang-tidy/checks/bugprone/optional-value-conversion>` check to detect conversion in argument of ``std::make_optional``. diff --git a/clang-tools-extra/docs/clang-tidy/checks/bugprone/multi-level-implicit-pointer-conversion.rst b/clang-tools-extra/docs/clang-tidy/checks/bugprone/multi-level-implicit-pointer-conversion.rst index e6dc5c13aa025..a226654c9ab75 100644 --- a/clang-tools-extra/docs/clang-tidy/checks/bugprone/multi-level-implicit-pointer-conversion.rst +++ b/clang-tools-extra/docs/clang-tidy/checks/bugprone/multi-level-implicit-pointer-conversion.rst @@ -42,3 +42,12 @@ Additionally, it is recommended that developers thoroughly check and verify the safety of the conversion before using an explicit cast. This extra level of caution can help catch potential issues early on in the development process, improving the overall reliability and maintainability of the code. + +.. note:: + + This check is enabled only for C++ code, not for C code. The motivation is the + type of conversions that this check warns about are fairly common and + idiomatic in C, and there are no safer alternatives. This introduces quite + some friction in the form of suppressions or casts. The check remains active + in C++ to more easily detect C-style patterns that can potentially be + refactored to use safer C++ constructs. _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits