Skip to content

Commit e1c3f4b

Browse files
author
Carlos Gálvez
committed
[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
1 parent 172c281 commit e1c3f4b

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed

clang-tools-extra/clang-tidy/bugprone/MultiLevelImplicitPointerConversionCheck.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ class MultiLevelImplicitPointerConversionCheck : public ClangTidyCheck {
2626
void registerMatchers(ast_matchers::MatchFinder *Finder) override;
2727
void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
2828
std::optional<TraversalKind> getCheckTraversalKind() const override;
29+
bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
30+
return LangOpts.CPlusPlus;
31+
}
2932
};
3033

3134
} // namespace clang::tidy::bugprone

clang-tools-extra/docs/ReleaseNotes.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,10 @@ New check aliases
148148
Changes in existing checks
149149
^^^^^^^^^^^^^^^^^^^^^^^^^^
150150

151+
- Disabled :doc:`bugprone-multi-level-implicit-pointer-conversion
152+
<clang-tidy/checks/bugprone/multi-level-implicit-pointer-conversion>` check in
153+
C code. The check is now only active in C++ code.
154+
151155
- Improved :doc:`bugprone-optional-value-conversion
152156
<clang-tidy/checks/bugprone/optional-value-conversion>` check to detect
153157
conversion in argument of ``std::make_optional``.

clang-tools-extra/docs/clang-tidy/checks/bugprone/multi-level-implicit-pointer-conversion.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,12 @@ Additionally, it is recommended that developers thoroughly check and verify the
4242
safety of the conversion before using an explicit cast. This extra level of
4343
caution can help catch potential issues early on in the development process,
4444
improving the overall reliability and maintainability of the code.
45+
46+
.. note::
47+
48+
This check is enabled only for C++ code, not for C code. The motivation is the
49+
type of conversions that this check warns about are fairly common and
50+
idiomatic in C, and there are no safer alternatives. This introduces quite
51+
some friction in the form of suppressions or casts. The check remains active
52+
in C++ to more easily detect C-style patterns that can potentially be
53+
refactored to use safer C++ constructs.

0 commit comments

Comments
 (0)