[clang-tools-extra] [clang-tidy] Don't warn on misplaced-widening-cast for provably non-o… (PR #208162)
via cfe-commits
cfe-commits at lists.llvm.org
Wed Jul 8 05:56:34 PDT 2026
github-actions[bot] wrote:
<!--LLVM CODE FORMAT COMMENT: {clang-format}-->
:warning: C/C++ code formatter, clang-format found issues in your code. :warning:
<details>
<summary>
You can test this locally with the following command:
</summary>
``````````bash
git-clang-format --diff origin/main HEAD --extensions cpp,h -- clang-tools-extra/clang-tidy/bugprone/MisplacedWideningCastCheck.cpp clang-tools-extra/clang-tidy/bugprone/MisplacedWideningCastCheck.h clang-tools-extra/test/clang-tidy/checkers/bugprone/misplaced-widening-cast-explicit-only.cpp --diff_from_common_commit
``````````
:warning:
The reproduction instructions above might return results for more than one PR
in a stack if you are using a stacked PR workflow. You can limit the results by
changing `origin/main` to the base branch/commit you want to compare against.
:warning:
</details>
<details>
<summary>
View the diff from clang-format here.
</summary>
``````````diff
diff --git a/clang-tools-extra/clang-tidy/bugprone/MisplacedWideningCastCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/MisplacedWideningCastCheck.cpp
index 378f36811..0478574ed 100644
--- a/clang-tools-extra/clang-tidy/bugprone/MisplacedWideningCastCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/MisplacedWideningCastCheck.cpp
@@ -18,12 +18,14 @@ MisplacedWideningCastCheck::MisplacedWideningCastCheck(
StringRef Name, ClangTidyContext *Context)
: ClangTidyCheck(Name, Context),
CheckImplicitCasts(Options.get("CheckImplicitCasts", false)),
- IgnoreConstexprOverflowProven(Options.get("IgnoreConstexprOverflowProven", false)) {}
+ IgnoreConstexprOverflowProven(
+ Options.get("IgnoreConstexprOverflowProven", false)) {}
void MisplacedWideningCastCheck::storeOptions(
ClangTidyOptions::OptionMap &Opts) {
Options.store(Opts, "CheckImplicitCasts", CheckImplicitCasts);
- Options.store(Opts, "IgnoreConstexprOverflowProven", IgnoreConstexprOverflowProven);
+ Options.store(Opts, "IgnoreConstexprOverflowProven",
+ IgnoreConstexprOverflowProven);
}
void MisplacedWideningCastCheck::registerMatchers(MatchFinder *Finder) {
@@ -56,14 +58,15 @@ void MisplacedWideningCastCheck::registerMatchers(MatchFinder *Finder) {
binaryOperator(isComparisonOperator(), hasEitherOperand(Cast)), this);
}
-static unsigned getMaxCalculationWidth(const ASTContext &Context,
- const Expr *E,
+static unsigned getMaxCalculationWidth(const ASTContext &Context, const Expr *E,
bool IgnoreConstexprOverflowProven) {
E = E->IgnoreParenImpCasts();
if (const auto *Bop = dyn_cast<BinaryOperator>(E)) {
- const unsigned LHSWidth = getMaxCalculationWidth(Context, Bop->getLHS(),IgnoreConstexprOverflowProven);
- const unsigned RHSWidth = getMaxCalculationWidth(Context, Bop->getRHS(),IgnoreConstexprOverflowProven);
+ const unsigned LHSWidth = getMaxCalculationWidth(
+ Context, Bop->getLHS(), IgnoreConstexprOverflowProven);
+ const unsigned RHSWidth = getMaxCalculationWidth(
+ Context, Bop->getRHS(), IgnoreConstexprOverflowProven);
if (Bop->getOpcode() == BO_Mul)
return LHSWidth + RHSWidth;
if (Bop->getOpcode() == BO_Add)
``````````
</details>
https://github.com/llvm/llvm-project/pull/208162
More information about the cfe-commits
mailing list