From 7a3cbb299772b886cbc14e9c5c3030400675aea3 Mon Sep 17 00:00:00 2001 From: David Blaikie Date: Mon, 9 Mar 2015 02:02:07 +0000 Subject: [PATCH] Simplify boolean expressions in clang with clang-tidy Patch by Richard (legalize at xmission dot com). Differential Revision: http://reviews.llvm.org/D8155 llvm-svn: 231619 --- clang/lib/AST/Type.cpp | 2 +- clang/lib/Analysis/CFG.cpp | 4 ++-- clang/lib/Basic/DiagnosticIDs.cpp | 2 +- clang/lib/Driver/ToolChain.cpp | 5 +---- clang/lib/Lex/PreprocessingRecord.cpp | 7 ++----- clang/lib/Parse/ParseDecl.cpp | 2 +- clang/lib/Sema/SemaOverload.cpp | 5 +---- 7 files changed, 9 insertions(+), 18 deletions(-) diff --git a/clang/lib/AST/Type.cpp b/clang/lib/AST/Type.cpp index 67c09cb..6e1d683 100644 --- a/clang/lib/AST/Type.cpp +++ b/clang/lib/AST/Type.cpp @@ -1713,7 +1713,7 @@ bool FunctionProtoType::isNothrow(const ASTContext &Ctx, if (EST == EST_DynamicNone || EST == EST_BasicNoexcept) return true; - if (EST == EST_Dynamic && ResultIfDependent == true) { + if (EST == EST_Dynamic && ResultIfDependent) { // A dynamic exception specification is throwing unless every exception // type is an (unexpanded) pack expansion type. for (unsigned I = 0, N = NumExceptions; I != N; ++I) diff --git a/clang/lib/Analysis/CFG.cpp b/clang/lib/Analysis/CFG.cpp index 5d06634..169f1df 100644 --- a/clang/lib/Analysis/CFG.cpp +++ b/clang/lib/Analysis/CFG.cpp @@ -841,12 +841,12 @@ private: // must be false. llvm::APSInt IntVal; if (Bop->getLHS()->EvaluateAsInt(IntVal, *Context)) { - if (IntVal.getBoolValue() == false) { + if (!IntVal.getBoolValue()) { return TryResult(false); } } if (Bop->getRHS()->EvaluateAsInt(IntVal, *Context)) { - if (IntVal.getBoolValue() == false) { + if (!IntVal.getBoolValue()) { return TryResult(false); } } diff --git a/clang/lib/Basic/DiagnosticIDs.cpp b/clang/lib/Basic/DiagnosticIDs.cpp index 1c68375..643503b 100644 --- a/clang/lib/Basic/DiagnosticIDs.cpp +++ b/clang/lib/Basic/DiagnosticIDs.cpp @@ -528,7 +528,7 @@ static bool getDiagnosticsInGroup(diag::Flavor Flavor, // An empty group is considered to be a warning group: we have empty groups // for GCC compatibility, and GCC does not have remarks. if (!Group->Members && !Group->SubGroups) - return Flavor == diag::Flavor::Remark ? true : false; + return Flavor == diag::Flavor::Remark; bool NotFound = true; diff --git a/clang/lib/Driver/ToolChain.cpp b/clang/lib/Driver/ToolChain.cpp index 5feeda4..d71b903 100644 --- a/clang/lib/Driver/ToolChain.cpp +++ b/clang/lib/Driver/ToolChain.cpp @@ -297,10 +297,7 @@ std::string ToolChain::ComputeLLVMTriple(const ArgList &Args, // '-mbig-endian'/'-EB'. if (Arg *A = Args.getLastArg(options::OPT_mlittle_endian, options::OPT_mbig_endian)) { - if (A->getOption().matches(options::OPT_mlittle_endian)) - IsBigEndian = false; - else - IsBigEndian = true; + IsBigEndian = !A->getOption().matches(options::OPT_mlittle_endian); } // Thumb2 is the default for V7 on Darwin. diff --git a/clang/lib/Lex/PreprocessingRecord.cpp b/clang/lib/Lex/PreprocessingRecord.cpp index 7abd340..c5f042a 100644 --- a/clang/lib/Lex/PreprocessingRecord.cpp +++ b/clang/lib/Lex/PreprocessingRecord.cpp @@ -73,11 +73,8 @@ static bool isPreprocessedEntityIfInFileID(PreprocessedEntity *PPE, FileID FID, SourceLocation Loc = PPE->getSourceRange().getBegin(); if (Loc.isInvalid()) return false; - - if (SM.isInFileID(SM.getFileLoc(Loc), FID)) - return true; - else - return false; + + return SM.isInFileID(SM.getFileLoc(Loc), FID); } /// \brief Returns true if the preprocessed entity that \arg PPEI iterator diff --git a/clang/lib/Parse/ParseDecl.cpp b/clang/lib/Parse/ParseDecl.cpp index b6264d4..cea5824 100644 --- a/clang/lib/Parse/ParseDecl.cpp +++ b/clang/lib/Parse/ParseDecl.cpp @@ -547,7 +547,7 @@ void Parser::ParseMicrosoftDeclSpec(ParsedAttributes &Attrs) { // We expect either a well-known identifier or a generic string. Anything // else is a malformed declspec. - bool IsString = Tok.getKind() == tok::string_literal ? true : false; + bool IsString = Tok.getKind() == tok::string_literal; if (!IsString && Tok.getKind() != tok::identifier && Tok.getKind() != tok::kw_restrict) { Diag(Tok, diag::err_ms_declspec_type); diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp index 664b6a4..4697876 100644 --- a/clang/lib/Sema/SemaOverload.cpp +++ b/clang/lib/Sema/SemaOverload.cpp @@ -9497,10 +9497,7 @@ struct CompareOverloadCandidatesForDisplay { numLFixes = (numLFixes == 0) ? UINT_MAX : numLFixes; numRFixes = (numRFixes == 0) ? UINT_MAX : numRFixes; if (numLFixes != numRFixes) { - if (numLFixes < numRFixes) - return true; - else - return false; + return numLFixes < numRFixes; } // If there's any ordering between the defined conversions... -- 2.7.4