diff options
Diffstat (limited to 'clang/lib/Sema/SemaChecking.cpp')
-rw-r--r-- | clang/lib/Sema/SemaChecking.cpp | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp index 7f45533..a5e0094 100644 --- a/clang/lib/Sema/SemaChecking.cpp +++ b/clang/lib/Sema/SemaChecking.cpp @@ -11647,6 +11647,15 @@ static void DiagnoseFloatingImpCast(Sema &S, Expr *E, QualType T, } } +static void CheckCommaOperand(Sema &S, Expr *E, QualType T, SourceLocation CC, + bool ExtraCheckForImplicitConversion) { + E = E->IgnoreParenImpCasts(); + AnalyzeImplicitConversions(S, E, CC); + + if (ExtraCheckForImplicitConversion && E->getType() != T) + S.CheckImplicitConversion(E, T, CC); +} + /// Analyze the given compound assignment for the possible losing of /// floating-point precision. static void AnalyzeCompoundAssignment(Sema &S, BinaryOperator *E) { @@ -12464,7 +12473,7 @@ static void AnalyzeImplicitConversions( << OrigE->getSourceRange() << T->isBooleanType() << FixItHint::CreateReplacement(UO->getBeginLoc(), "!"); - if (const auto *BO = dyn_cast<BinaryOperator>(SourceExpr)) + if (auto *BO = dyn_cast<BinaryOperator>(SourceExpr)) if ((BO->getOpcode() == BO_And || BO->getOpcode() == BO_Or) && BO->getLHS()->isKnownToHaveBooleanValue() && BO->getRHS()->isKnownToHaveBooleanValue() && @@ -12490,6 +12499,19 @@ static void AnalyzeImplicitConversions( (BO->getOpcode() == BO_And ? "&&" : "||")); S.Diag(BO->getBeginLoc(), diag::note_cast_operand_to_int); } + } else if (BO->isCommaOp() && !S.getLangOpts().CPlusPlus) { + /// Analyze the given comma operator. The basic idea behind the analysis + /// is to analyze the left and right operands slightly differently. The + /// left operand needs to check whether the operand itself has an implicit + /// conversion, but not whether the left operand induces an implicit + /// conversion for the entire comma expression itself. This is similar to + /// how CheckConditionalOperand behaves; it's as-if the correct operand + /// were directly used for the implicit conversion check. + CheckCommaOperand(S, BO->getLHS(), T, BO->getOperatorLoc(), + /*ExtraCheckForImplicitConversion=*/false); + CheckCommaOperand(S, BO->getRHS(), T, BO->getOperatorLoc(), + /*ExtraCheckForImplicitConversion=*/true); + return; } // For conditional operators, we analyze the arguments as if they |