diff options
Diffstat (limited to 'clang/lib/Sema/SemaChecking.cpp')
-rw-r--r-- | clang/lib/Sema/SemaChecking.cpp | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp index ea4f3476b6c..31b643f1385 100644 --- a/clang/lib/Sema/SemaChecking.cpp +++ b/clang/lib/Sema/SemaChecking.cpp @@ -6559,6 +6559,13 @@ void AnalyzeImplicitConversions(Sema &S, Expr *OrigE, SourceLocation CC) { continue; AnalyzeImplicitConversions(S, ChildExpr, CC); } + if (BO && BO->isLogicalOp()) { + S.CheckBoolLikeConversion(BO->getLHS(), BO->getLHS()->getExprLoc()); + S.CheckBoolLikeConversion(BO->getRHS(), BO->getRHS()->getExprLoc()); + } + if (const UnaryOperator *U = dyn_cast<UnaryOperator>(E)) + if (U->getOpcode() == UO_LNot) + S.CheckBoolLikeConversion(U->getSubExpr(), CC); } } // end anonymous namespace @@ -6617,6 +6624,18 @@ static bool IsInAnyMacroBody(const SourceManager &SM, SourceLocation Loc) { return false; } +/// CheckBoolLikeConversion - Check conversion of given expression to boolean. +/// Input argument E is a logical expression. +static void CheckBoolLikeConversion(Sema &S, Expr *E, SourceLocation CC) { + if (S.getLangOpts().Bool) + return; + CheckImplicitConversion(S, E->IgnoreParenImpCasts(), S.Context.BoolTy, CC); +} + +void Sema::CheckBoolLikeConversion(Expr *E, SourceLocation CC) { + ::CheckBoolLikeConversion(*this, E, CC); +} + /// \brief Diagnose pointers that are always non-null. /// \param E the expression containing the pointer /// \param NullKind NPCK_NotNull if E is a cast to bool, otherwise, E is |