[clang] [clang] Diagnose for implicit boolean conversions in assignments (PR #114687)
via cfe-commits
cfe-commits at lists.llvm.org
Sat Nov 2 15:52:00 PDT 2024
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 8129ba6c70aef54d87893adeb34e76f84fa69fe3 b8244b346c7a97c2eb35ccfea23675b8df4f046e --extensions cpp,h -- clang/include/clang/Sema/Sema.h clang/lib/Sema/Sema.cpp clang/lib/Sema/SemaExprCXX.cpp
``````````
</details>
<details>
<summary>
View the diff from clang-format here.
</summary>
``````````diff
diff --git a/clang/lib/Sema/Sema.cpp b/clang/lib/Sema/Sema.cpp
index cc9cb173c0..934812dcc0 100644
--- a/clang/lib/Sema/Sema.cpp
+++ b/clang/lib/Sema/Sema.cpp
@@ -687,13 +687,13 @@ void Sema::diagnoseZeroToNullptrConversion(CastKind Kind, const Expr *E) {
<< FixItHint::CreateReplacement(E->getSourceRange(), "nullptr");
}
-void Sema::DiagnoseImplicitCastBoolAssignment(Expr* E,QualType Ty) {
+void Sema::DiagnoseImplicitCastBoolAssignment(Expr *E, QualType Ty) {
if (Ty->isBooleanType()) {
- if (BinaryOperator* Op = dyn_cast<BinaryOperator>(E)) {
+ if (BinaryOperator *Op = dyn_cast<BinaryOperator>(E)) {
// should only be issued for regular assignment `=`, not for e.g `+=`
if (Op->getOpcode() == BO_Assign) {
SourceLocation Loc = Op->getOperatorLoc();
- Diag(Loc,diag::warn_parens_bool_assign) << E->getSourceRange();
+ Diag(Loc, diag::warn_parens_bool_assign) << E->getSourceRange();
}
}
}
@@ -773,7 +773,7 @@ ExprResult Sema::ImpCastExprToType(Expr *E, QualType Ty,
}
}
- DiagnoseImplicitCastBoolAssignment(E,Ty);
+ DiagnoseImplicitCastBoolAssignment(E, Ty);
if (ImplicitCastExpr *ImpCast = dyn_cast<ImplicitCastExpr>(E)) {
if (ImpCast->getCastKind() == Kind && (!BasePath || BasePath->empty())) {
diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index 14ca6a7430..1edce04ed7 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -4393,7 +4393,7 @@ Sema::PerformImplicitConversion(Expr *From, QualType ToType,
FromType = From->getType();
}
- DiagnoseImplicitCastBoolAssignment(From,ToType);
+ DiagnoseImplicitCastBoolAssignment(From, ToType);
// If we're converting to an atomic type, first convert to the corresponding
// non-atomic type.
``````````
</details>
https://github.com/llvm/llvm-project/pull/114687
More information about the cfe-commits
mailing list