[clang-tidy][NFC] Remove redundant braces with clang-format 'RemoveBracesLLVM' (N/N) (#172754)
This commit is contained in:
parent
031e9c989e
commit
6a470bfd7c
@ -125,9 +125,8 @@ BracesAroundStatementsCheck::findRParenLoc(const IfOrWhileStmt *S,
|
||||
if (const DeclStmt *CondVar = S->getConditionVariableDeclStmt())
|
||||
CondEndLoc = CondVar->getEndLoc();
|
||||
|
||||
if (!CondEndLoc.isValid()) {
|
||||
if (!CondEndLoc.isValid())
|
||||
return {};
|
||||
}
|
||||
|
||||
const SourceLocation PastCondEndLoc =
|
||||
Lexer::getLocForEndOfToken(CondEndLoc, 0, SM, LangOpts);
|
||||
|
||||
@ -278,21 +278,18 @@ void ContainerSizeEmptyCheck::check(const MatchFinder::MatchResult &Result) {
|
||||
ReplacementText += ".empty()";
|
||||
|
||||
if (BinCmp) {
|
||||
if (BinCmp->getOperator() == OO_ExclaimEqual) {
|
||||
if (BinCmp->getOperator() == OO_ExclaimEqual)
|
||||
ReplacementText = "!" + ReplacementText;
|
||||
}
|
||||
Hint =
|
||||
FixItHint::CreateReplacement(BinCmp->getSourceRange(), ReplacementText);
|
||||
} else if (BinCmpTempl) {
|
||||
if (BinCmpTempl->getOpcode() == BinaryOperatorKind::BO_NE) {
|
||||
if (BinCmpTempl->getOpcode() == BinaryOperatorKind::BO_NE)
|
||||
ReplacementText = "!" + ReplacementText;
|
||||
}
|
||||
Hint = FixItHint::CreateReplacement(BinCmpTempl->getSourceRange(),
|
||||
ReplacementText);
|
||||
} else if (BinCmpRewritten) {
|
||||
if (BinCmpRewritten->getOpcode() == BinaryOperatorKind::BO_NE) {
|
||||
if (BinCmpRewritten->getOpcode() == BinaryOperatorKind::BO_NE)
|
||||
ReplacementText = "!" + ReplacementText;
|
||||
}
|
||||
Hint = FixItHint::CreateReplacement(BinCmpRewritten->getSourceRange(),
|
||||
ReplacementText);
|
||||
} else if (BinaryOp) { // Determine the correct transformation.
|
||||
@ -400,10 +397,9 @@ void ContainerSizeEmptyCheck::check(const MatchFinder::MatchResult &Result) {
|
||||
Result.Nodes.getNodeAs<CXXDependentScopeMemberExpr>(
|
||||
"MemberExpr"))
|
||||
Diag << DependentExpr->getMember();
|
||||
else if (const auto *ME =
|
||||
Result.Nodes.getNodeAs<MemberExpr>("MemberExpr")) {
|
||||
else if (const auto *ME = Result.Nodes.getNodeAs<MemberExpr>("MemberExpr"))
|
||||
Diag << ME->getMemberNameInfo().getName();
|
||||
} else
|
||||
else
|
||||
Diag << "unknown method";
|
||||
Diag << Hint;
|
||||
} else {
|
||||
|
||||
@ -80,10 +80,9 @@ DuplicateIncludeCallbacks::DuplicateIncludeCallbacks(
|
||||
Files.emplace_back();
|
||||
|
||||
AllowedRegexes.reserve(IgnoredList.size());
|
||||
for (const StringRef &It : IgnoredList) {
|
||||
for (const StringRef &It : IgnoredList)
|
||||
if (!It.empty())
|
||||
AllowedRegexes.emplace_back(It);
|
||||
}
|
||||
}
|
||||
|
||||
void DuplicateIncludeCallbacks::FileChanged(SourceLocation Loc,
|
||||
|
||||
@ -53,10 +53,9 @@ static const DeclRefExpr *findUsage(const Stmt *Node, int64_t DeclIdentifier) {
|
||||
if (DeclRef->getDecl()->getID() == DeclIdentifier)
|
||||
return DeclRef;
|
||||
} else {
|
||||
for (const Stmt *ChildNode : Node->children()) {
|
||||
for (const Stmt *ChildNode : Node->children())
|
||||
if (const DeclRefExpr *Result = findUsage(ChildNode, DeclIdentifier))
|
||||
return Result;
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
@ -70,11 +69,10 @@ findUsageRange(const Stmt *Node,
|
||||
if (llvm::is_contained(DeclIdentifiers, DeclRef->getDecl()->getID()))
|
||||
return DeclRef;
|
||||
} else {
|
||||
for (const Stmt *ChildNode : Node->children()) {
|
||||
for (const Stmt *ChildNode : Node->children())
|
||||
if (const DeclRefExpr *Result =
|
||||
findUsageRange(ChildNode, DeclIdentifiers))
|
||||
return Result;
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@ -319,10 +319,9 @@ std::string IdentifierNamingCheck::HungarianNotation::getDeclTypeName(
|
||||
|
||||
const char *const PosList[] = {strchr(Begin, '='), strchr(Begin, ';'),
|
||||
strchr(Begin, ','), strchr(Begin, ')'), EOL};
|
||||
for (const auto &Pos : PosList) {
|
||||
for (const auto &Pos : PosList)
|
||||
if (Pos > Begin)
|
||||
EOL = std::min(EOL, Pos);
|
||||
}
|
||||
|
||||
StrLen = EOL - Begin;
|
||||
std::string TypeName;
|
||||
@ -340,18 +339,15 @@ std::string IdentifierNamingCheck::HungarianNotation::getDeclTypeName(
|
||||
"virtual"};
|
||||
|
||||
// Remove keywords
|
||||
for (const StringRef Kw : Keywords) {
|
||||
for (size_t Pos = 0; (Pos = Type.find(Kw, Pos)) != std::string::npos;) {
|
||||
for (const StringRef Kw : Keywords)
|
||||
for (size_t Pos = 0; (Pos = Type.find(Kw, Pos)) != std::string::npos;)
|
||||
Type.replace(Pos, Kw.size(), "");
|
||||
}
|
||||
}
|
||||
TypeName = Type.erase(0, Type.find_first_not_of(' '));
|
||||
|
||||
// Remove template parameters
|
||||
const size_t Pos = Type.find('<');
|
||||
if (Pos != std::string::npos) {
|
||||
if (Pos != std::string::npos)
|
||||
TypeName = Type.erase(Pos, Type.size() - Pos);
|
||||
}
|
||||
|
||||
// Replace spaces with single space.
|
||||
for (size_t Pos = 0; (Pos = Type.find(" ", Pos)) != std::string::npos;
|
||||
@ -699,10 +695,9 @@ size_t IdentifierNamingCheck::HungarianNotation::getAsteriskCount(
|
||||
const std::string &TypeName) const {
|
||||
size_t Pos = TypeName.find('*');
|
||||
size_t Count = 0;
|
||||
for (; Pos < TypeName.length(); Pos++, Count++) {
|
||||
for (; Pos < TypeName.length(); Pos++, Count++)
|
||||
if ('*' != TypeName[Pos])
|
||||
break;
|
||||
}
|
||||
return Count;
|
||||
}
|
||||
|
||||
@ -941,9 +936,8 @@ std::string IdentifierNamingCheck::fixupWithCase(
|
||||
if (Words.empty())
|
||||
return Name.str();
|
||||
|
||||
if (IdentifierNamingCheck::HungarianPrefixType::HPT_Off != Style.HPType) {
|
||||
if (IdentifierNamingCheck::HungarianPrefixType::HPT_Off != Style.HPType)
|
||||
HungarianNotation.removeDuplicatedPrefix(Words, HNOption);
|
||||
}
|
||||
|
||||
SmallString<128> Fixup;
|
||||
switch (Case) {
|
||||
@ -1199,9 +1193,8 @@ StyleKind IdentifierNamingCheck::findStyleKind(
|
||||
if (const auto *Decl = dyn_cast<FieldDecl>(D)) {
|
||||
if (CheckAnonFieldInParentScope) {
|
||||
const RecordDecl *Record = Decl->getParent();
|
||||
if (Record->isAnonymousStructOrUnion()) {
|
||||
if (Record->isAnonymousStructOrUnion())
|
||||
return findStyleKindForAnonField(Decl, NamingStyles);
|
||||
}
|
||||
}
|
||||
|
||||
return findStyleKindForField(Decl, Decl->getType(), NamingStyles);
|
||||
@ -1240,9 +1233,8 @@ StyleKind IdentifierNamingCheck::findStyleKind(
|
||||
return SK_Invalid;
|
||||
}
|
||||
|
||||
if (const auto *Decl = dyn_cast<VarDecl>(D)) {
|
||||
if (const auto *Decl = dyn_cast<VarDecl>(D))
|
||||
return findStyleKindForVar(Decl, Decl->getType(), NamingStyles);
|
||||
}
|
||||
|
||||
if (const auto *Decl = dyn_cast<CXXMethodDecl>(D)) {
|
||||
if (Decl->isMain() || !Decl->isUserProvided() ||
|
||||
@ -1458,13 +1450,11 @@ StyleKind IdentifierNamingCheck::findStyleKindForAnonField(
|
||||
|
||||
const QualType Type = AnonField->getType();
|
||||
|
||||
if (const auto *F = dyn_cast<FieldDecl>(IFD->chain().front())) {
|
||||
if (const auto *F = dyn_cast<FieldDecl>(IFD->chain().front()))
|
||||
return findStyleKindForField(F, Type, NamingStyles);
|
||||
}
|
||||
|
||||
if (const auto *V = IFD->getVarDecl()) {
|
||||
if (const auto *V = IFD->getVarDecl())
|
||||
return findStyleKindForVar(V, Type, NamingStyles);
|
||||
}
|
||||
|
||||
return SK_Invalid;
|
||||
}
|
||||
|
||||
@ -98,28 +98,23 @@ static void fixGenericExprCastToBool(DiagnosticBuilder &Diag,
|
||||
|
||||
std::string StartLocInsertion;
|
||||
|
||||
if (NeedOuterParens) {
|
||||
if (NeedOuterParens)
|
||||
StartLocInsertion += "(";
|
||||
}
|
||||
if (NeedInnerParens) {
|
||||
if (NeedInnerParens)
|
||||
StartLocInsertion += "(";
|
||||
}
|
||||
|
||||
if (!StartLocInsertion.empty()) {
|
||||
if (!StartLocInsertion.empty())
|
||||
Diag << FixItHint::CreateInsertion(Cast->getBeginLoc(), StartLocInsertion);
|
||||
}
|
||||
|
||||
std::string EndLocInsertion;
|
||||
|
||||
if (NeedInnerParens) {
|
||||
if (NeedInnerParens)
|
||||
EndLocInsertion += ")";
|
||||
}
|
||||
|
||||
if (InvertComparison) {
|
||||
if (InvertComparison)
|
||||
EndLocInsertion += " == ";
|
||||
} else {
|
||||
else
|
||||
EndLocInsertion += " != ";
|
||||
}
|
||||
|
||||
const StringRef ZeroLiteral = getZeroLiteralToCompareWithForType(
|
||||
Cast->getCastKind(), SubExpr->getType(), Context);
|
||||
@ -129,9 +124,8 @@ static void fixGenericExprCastToBool(DiagnosticBuilder &Diag,
|
||||
else
|
||||
EndLocInsertion += ZeroLiteral;
|
||||
|
||||
if (NeedOuterParens) {
|
||||
if (NeedOuterParens)
|
||||
EndLocInsertion += ")";
|
||||
}
|
||||
|
||||
const SourceLocation EndLoc = Lexer::getLocForEndOfToken(
|
||||
Cast->getEndLoc(), 0, Context.getSourceManager(), Context.getLangOpts());
|
||||
@ -140,14 +134,11 @@ static void fixGenericExprCastToBool(DiagnosticBuilder &Diag,
|
||||
|
||||
static StringRef getEquivalentBoolLiteralForExpr(const Expr *Expression,
|
||||
ASTContext &Context) {
|
||||
if (isNULLMacroExpansion(Expression, Context)) {
|
||||
if (isNULLMacroExpansion(Expression, Context))
|
||||
return "false";
|
||||
}
|
||||
|
||||
if (const auto *IntLit =
|
||||
dyn_cast<IntegerLiteral>(Expression->IgnoreParens())) {
|
||||
if (const auto *IntLit = dyn_cast<IntegerLiteral>(Expression->IgnoreParens()))
|
||||
return (IntLit->getValue() == 0) ? "false" : "true";
|
||||
}
|
||||
|
||||
if (const auto *FloatLit = dyn_cast<FloatingLiteral>(Expression)) {
|
||||
llvm::APFloat FloatLitAbsValue = FloatLit->getValue();
|
||||
@ -155,13 +146,11 @@ static StringRef getEquivalentBoolLiteralForExpr(const Expr *Expression,
|
||||
return (FloatLitAbsValue.bitcastToAPInt() == 0) ? "false" : "true";
|
||||
}
|
||||
|
||||
if (const auto *CharLit = dyn_cast<CharacterLiteral>(Expression)) {
|
||||
if (const auto *CharLit = dyn_cast<CharacterLiteral>(Expression))
|
||||
return (CharLit->getValue() == 0) ? "false" : "true";
|
||||
}
|
||||
|
||||
if (isa<StringLiteral>(Expression->IgnoreCasts())) {
|
||||
if (isa<StringLiteral>(Expression->IgnoreCasts()))
|
||||
return "true";
|
||||
}
|
||||
|
||||
return {};
|
||||
}
|
||||
@ -217,15 +206,13 @@ getEquivalentForBoolLiteral(const CXXBoolLiteralExpr *BoolLiteral,
|
||||
}
|
||||
|
||||
if (DestType->isFloatingType()) {
|
||||
if (ASTContext::hasSameType(DestType, Context.FloatTy)) {
|
||||
if (ASTContext::hasSameType(DestType, Context.FloatTy))
|
||||
return BoolLiteral->getValue() ? "1.0f" : "0.0f";
|
||||
}
|
||||
return BoolLiteral->getValue() ? "1.0" : "0.0";
|
||||
}
|
||||
|
||||
if (DestType->isUnsignedIntegerType()) {
|
||||
if (DestType->isUnsignedIntegerType())
|
||||
return BoolLiteral->getValue() ? "1u" : "0u";
|
||||
}
|
||||
return BoolLiteral->getValue() ? "1" : "0";
|
||||
}
|
||||
|
||||
|
||||
@ -184,11 +184,9 @@ getParameterSourceDeclaration(const FunctionDecl *OriginalDeclaration) {
|
||||
if (OriginalDeclaration->isThisDeclarationADefinition())
|
||||
return OriginalDeclaration;
|
||||
|
||||
for (const FunctionDecl *OtherDeclaration : OriginalDeclaration->redecls()) {
|
||||
if (OtherDeclaration->isThisDeclarationADefinition()) {
|
||||
for (const FunctionDecl *OtherDeclaration : OriginalDeclaration->redecls())
|
||||
if (OtherDeclaration->isThisDeclarationADefinition())
|
||||
return OtherDeclaration;
|
||||
}
|
||||
}
|
||||
|
||||
// No definition found, so return original declaration.
|
||||
return OriginalDeclaration;
|
||||
|
||||
@ -187,9 +187,8 @@ bool MagicNumbersCheck::isConstant(const MatchFinder::MatchResult &Result,
|
||||
}
|
||||
|
||||
bool MagicNumbersCheck::isIgnoredValue(const IntegerLiteral *Literal) const {
|
||||
if (Literal->getType()->isBitIntType()) {
|
||||
if (Literal->getType()->isBitIntType())
|
||||
return true;
|
||||
}
|
||||
const llvm::APInt IntValue = Literal->getValue();
|
||||
const int64_t Value = IntValue.getZExtValue();
|
||||
if (Value == 0)
|
||||
|
||||
@ -178,9 +178,8 @@ public:
|
||||
|
||||
// Look through deref of this.
|
||||
if (const auto *UnOp = dyn_cast_or_null<UnaryOperator>(Parent)) {
|
||||
if (UnOp->getOpcode() == UO_Deref) {
|
||||
if (UnOp->getOpcode() == UO_Deref)
|
||||
Parent = getParentExprIgnoreParens(UnOp);
|
||||
}
|
||||
}
|
||||
|
||||
// It's okay to
|
||||
|
||||
@ -110,10 +110,9 @@ void NamespaceCommentCheck::check(const MatchFinder::MatchResult &Result) {
|
||||
// Currently for nested namespace (n1::n2::...) the AST matcher will match foo
|
||||
// then bar instead of a single match. So if we got a nested namespace we have
|
||||
// to skip the next ones.
|
||||
for (const SourceLocation &EndOfNameLocation : Ends) {
|
||||
for (const SourceLocation &EndOfNameLocation : Ends)
|
||||
if (Sources.isBeforeInTranslationUnit(ND->getLocation(), EndOfNameLocation))
|
||||
return;
|
||||
}
|
||||
|
||||
std::optional<std::string> NamespaceNameAsWritten =
|
||||
getNamespaceNameAsWritten(LBraceLoc, Sources, getLangOpts());
|
||||
|
||||
@ -59,9 +59,8 @@ void NonConstParameterCheck::check(const MatchFinder::MatchResult &Result) {
|
||||
// Typically, if a parameter is const then it is fine to make the data
|
||||
// const. But sometimes the data is written even though the parameter
|
||||
// is const. Mark all data passed by address to the function.
|
||||
for (const auto *Arg : CE->arguments()) {
|
||||
for (const auto *Arg : CE->arguments())
|
||||
markCanNotBeConst(Arg->IgnoreParenCasts(), true);
|
||||
}
|
||||
|
||||
// Data passed by nonconst reference should not be made const.
|
||||
if (const FunctionDecl *FD = CE->getDirectCallee()) {
|
||||
@ -78,9 +77,8 @@ void NonConstParameterCheck::check(const MatchFinder::MatchResult &Result) {
|
||||
}
|
||||
}
|
||||
} else if (const auto *CE = dyn_cast<CXXConstructExpr>(S)) {
|
||||
for (const auto *Arg : CE->arguments()) {
|
||||
for (const auto *Arg : CE->arguments())
|
||||
markCanNotBeConst(Arg->IgnoreParenCasts(), true);
|
||||
}
|
||||
// Data passed by nonconst reference should not be made const.
|
||||
unsigned ArgNr = 0U;
|
||||
if (const auto *CD = CE->getConstructor()) {
|
||||
@ -216,10 +214,9 @@ void NonConstParameterCheck::markCanNotBeConst(const Expr *E,
|
||||
} else if (const auto *CLE = dyn_cast<CompoundLiteralExpr>(E)) {
|
||||
markCanNotBeConst(CLE->getInitializer(), true);
|
||||
} else if (const auto *Constr = dyn_cast<CXXConstructExpr>(E)) {
|
||||
for (const auto *Arg : Constr->arguments()) {
|
||||
for (const auto *Arg : Constr->arguments())
|
||||
if (const auto *M = dyn_cast<MaterializeTemporaryExpr>(Arg))
|
||||
markCanNotBeConst(cast<Expr>(M->getSubExpr()), CanNotBeConst);
|
||||
}
|
||||
} else if (const auto *ILE = dyn_cast<InitListExpr>(E)) {
|
||||
for (unsigned I = 0U; I < ILE->getNumInits(); ++I)
|
||||
markCanNotBeConst(ILE->getInit(I), true);
|
||||
|
||||
@ -228,10 +228,9 @@ void QualifiedAutoCheck::check(const MatchFinder::MatchResult &Result) {
|
||||
return;
|
||||
|
||||
SourceLocation FixitLoc = FixItRange.getBegin();
|
||||
for (const SourceRange &Range : RemoveQualifiersRange) {
|
||||
for (const SourceRange &Range : RemoveQualifiersRange)
|
||||
if (Range.getBegin() < FixitLoc)
|
||||
FixitLoc = Range.getBegin();
|
||||
}
|
||||
|
||||
const std::string ReplStr = [&] {
|
||||
const StringRef PtrConst = isPointerConst(Var->getType()) ? "const " : "";
|
||||
@ -249,9 +248,8 @@ void QualifiedAutoCheck::check(const MatchFinder::MatchResult &Result) {
|
||||
<< IsLocalConst << IsLocalVolatile << IsLocalRestrict << Var->getName()
|
||||
<< ReplStr;
|
||||
|
||||
for (const SourceRange &Range : RemoveQualifiersRange) {
|
||||
for (const SourceRange &Range : RemoveQualifiersRange)
|
||||
Diag << FixItHint::CreateRemoval(CharSourceRange::getCharRange(Range));
|
||||
}
|
||||
|
||||
Diag << FixItHint::CreateReplacement(FixItRange, ReplStr);
|
||||
return;
|
||||
|
||||
@ -77,17 +77,14 @@ static bool areBinaryOperatorOperandsTypesEqualToOperatorResultType(
|
||||
|
||||
static const Decl *getSourceExprDecl(const Expr *SourceExpr) {
|
||||
const Expr *CleanSourceExpr = SourceExpr->IgnoreParenImpCasts();
|
||||
if (const auto *E = dyn_cast<DeclRefExpr>(CleanSourceExpr)) {
|
||||
if (const auto *E = dyn_cast<DeclRefExpr>(CleanSourceExpr))
|
||||
return E->getDecl();
|
||||
}
|
||||
|
||||
if (const auto *E = dyn_cast<CallExpr>(CleanSourceExpr)) {
|
||||
if (const auto *E = dyn_cast<CallExpr>(CleanSourceExpr))
|
||||
return E->getCalleeDecl();
|
||||
}
|
||||
|
||||
if (const auto *E = dyn_cast<MemberExpr>(CleanSourceExpr)) {
|
||||
if (const auto *E = dyn_cast<MemberExpr>(CleanSourceExpr))
|
||||
return E->getMemberDecl();
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
@ -175,9 +175,8 @@ void RedundantSmartptrGetCheck::check(const MatchFinder::MatchResult &Result) {
|
||||
CharSourceRange::getTokenRange(Smartptr->getSourceRange()),
|
||||
*Result.SourceManager, getLangOpts());
|
||||
// Check if the last two characters are "->" and remove them
|
||||
if (SmartptrText.ends_with("->")) {
|
||||
if (SmartptrText.ends_with("->"))
|
||||
SmartptrText = SmartptrText.drop_back(2);
|
||||
}
|
||||
// Replace foo->get() with *foo, and foo.get() with foo.
|
||||
const std::string Replacement =
|
||||
Twine(IsPtrToPtr ? "*" : "", SmartptrText).str();
|
||||
|
||||
@ -70,10 +70,9 @@ static std::pair<OverloadedOperatorKind, StringRef> OperatorNames[] = {
|
||||
{OO_GreaterEqual, ">="}, {OO_Greater, ">"}, {OO_LessEqual, "<="}};
|
||||
|
||||
static StringRef getOperatorName(OverloadedOperatorKind OpKind) {
|
||||
for (auto Name : OperatorNames) {
|
||||
for (auto Name : OperatorNames)
|
||||
if (Name.first == OpKind)
|
||||
return Name.second;
|
||||
}
|
||||
|
||||
return {};
|
||||
}
|
||||
@ -247,10 +246,9 @@ static bool containsDiscardedTokens(const ASTContext &Context,
|
||||
Lex.SetCommentRetentionState(true);
|
||||
|
||||
Token Tok;
|
||||
while (!Lex.LexFromRawLexer(Tok)) {
|
||||
while (!Lex.LexFromRawLexer(Tok))
|
||||
if (Tok.is(tok::TokenKind::comment) || Tok.is(tok::TokenKind::hash))
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
@ -276,9 +274,8 @@ public:
|
||||
}
|
||||
|
||||
bool dataTraverseStmtPre(Stmt *S) {
|
||||
if (!S) {
|
||||
if (!S)
|
||||
return true;
|
||||
}
|
||||
if (Check->canBeBypassed(S))
|
||||
return false;
|
||||
if (!shouldIgnore(S))
|
||||
@ -920,13 +917,11 @@ static bool flipDemorganSide(SmallVectorImpl<FixItHint> &Fixes,
|
||||
FixItHint::CreateRemoval(cast<UnaryOperator>(E)->getOperatorLoc()));
|
||||
return false;
|
||||
}
|
||||
if (const auto *BinOp = dyn_cast<BinaryOperator>(E)) {
|
||||
if (const auto *BinOp = dyn_cast<BinaryOperator>(E))
|
||||
return flipDemorganBinaryOperator(Fixes, Ctx, BinOp, OuterBO);
|
||||
}
|
||||
if (const auto *Paren = dyn_cast<ParenExpr>(E)) {
|
||||
if (const auto *BinOp = dyn_cast<BinaryOperator>(Paren->getSubExpr())) {
|
||||
if (const auto *BinOp = dyn_cast<BinaryOperator>(Paren->getSubExpr()))
|
||||
return flipDemorganBinaryOperator(Fixes, Ctx, BinOp, OuterBO, Paren);
|
||||
}
|
||||
}
|
||||
// Fallback case just insert a logical not operator.
|
||||
if (E->getBeginLoc().isMacroID())
|
||||
|
||||
@ -38,9 +38,8 @@ void StringCompareCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
|
||||
}
|
||||
|
||||
void StringCompareCheck::registerMatchers(MatchFinder *Finder) {
|
||||
if (StringLikeClasses.empty()) {
|
||||
if (StringLikeClasses.empty())
|
||||
return;
|
||||
}
|
||||
const auto StrCompare = cxxMemberCallExpr(
|
||||
callee(cxxMethodDecl(hasName("compare"), ofClass(cxxRecordDecl(hasAnyName(
|
||||
StringLikeClasses))))),
|
||||
|
||||
@ -85,13 +85,12 @@ static QualType getReplacementCastType(const Expr *CondLhs, const Expr *CondRhs,
|
||||
RhsType.getCanonicalType().getNonReferenceType().getUnqualifiedType();
|
||||
QualType GlobalImplicitCastType;
|
||||
if (LhsCanonicalType != RhsCanonicalType) {
|
||||
if (llvm::isa<IntegerLiteral>(CondRhs)) {
|
||||
if (llvm::isa<IntegerLiteral>(CondRhs))
|
||||
GlobalImplicitCastType = getNonTemplateAlias(LhsType);
|
||||
} else if (llvm::isa<IntegerLiteral>(CondLhs)) {
|
||||
else if (llvm::isa<IntegerLiteral>(CondLhs))
|
||||
GlobalImplicitCastType = getNonTemplateAlias(RhsType);
|
||||
} else {
|
||||
else
|
||||
GlobalImplicitCastType = getNonTemplateAlias(ComparedType);
|
||||
}
|
||||
}
|
||||
return GlobalImplicitCastType;
|
||||
}
|
||||
|
||||
@ -24,13 +24,11 @@ const FunctionDecl *getSurroundingFunction(ASTContext &Context,
|
||||
|
||||
bool isBinaryOrTernary(const Expr *E) {
|
||||
const Expr *EBase = E->IgnoreImpCasts();
|
||||
if (isa<BinaryOperator>(EBase) || isa<ConditionalOperator>(EBase)) {
|
||||
if (isa<BinaryOperator>(EBase) || isa<ConditionalOperator>(EBase))
|
||||
return true;
|
||||
}
|
||||
|
||||
if (const auto *Operator = dyn_cast<CXXOperatorCallExpr>(EBase)) {
|
||||
if (const auto *Operator = dyn_cast<CXXOperatorCallExpr>(EBase))
|
||||
return Operator->isInfixBinaryOp();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -37,9 +37,8 @@ static bool isPtrOrReferenceForVar(const Stmt *S, const ValueDecl *Var) {
|
||||
if (const auto *DS = dyn_cast<DeclStmt>(S)) {
|
||||
for (const Decl *D : DS->getDeclGroup()) {
|
||||
if (const auto *LeftVar = dyn_cast<VarDecl>(D)) {
|
||||
if (LeftVar->hasInit() && LeftVar->getType()->isReferenceType()) {
|
||||
if (LeftVar->hasInit() && LeftVar->getType()->isReferenceType())
|
||||
return isAccessForVar(LeftVar->getInit(), Var);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (const auto *UnOp = dyn_cast<UnaryOperator>(S)) {
|
||||
|
||||
@ -70,9 +70,8 @@ static SourceLocation findEndLocation(const Stmt &S, const SourceManager &SM,
|
||||
|
||||
for (;;) {
|
||||
assert(Loc.isValid());
|
||||
while (isHorizontalWhitespace(*SM.getCharacterData(Loc))) {
|
||||
while (isHorizontalWhitespace(*SM.getCharacterData(Loc)))
|
||||
Loc = Loc.getLocWithOffset(1);
|
||||
}
|
||||
|
||||
if (isVerticalWhitespace(*SM.getCharacterData(Loc))) {
|
||||
// EOL, insert brace before.
|
||||
|
||||
@ -47,11 +47,10 @@ static bool hasSameParameterTypes(const CXXMethodDecl &D,
|
||||
const CXXMethodDecl &O) {
|
||||
if (D.getNumParams() != O.getNumParams())
|
||||
return false;
|
||||
for (int I = 0, E = D.getNumParams(); I < E; ++I) {
|
||||
for (int I = 0, E = D.getNumParams(); I < E; ++I)
|
||||
if (!isSameTypeIgnoringConst(D.getParamDecl(I)->getType(),
|
||||
O.getParamDecl(I)->getType()))
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -125,9 +124,8 @@ static bool isLikelyShallowConst(const CXXMethodDecl &M) {
|
||||
|
||||
// (A)
|
||||
const CXXMethodDecl *ConstOverload = findConstOverload(M);
|
||||
if (ConstOverload == nullptr) {
|
||||
if (ConstOverload == nullptr)
|
||||
return false;
|
||||
}
|
||||
|
||||
// (B)
|
||||
const QualType CallTy = M.getReturnType().getCanonicalType();
|
||||
@ -291,9 +289,8 @@ AST_MATCHER_P(DeclRefExpr, doesNotMutateObject, int, Indirections) {
|
||||
if (const auto *const OpCall = dyn_cast<CXXOperatorCallExpr>(P)) {
|
||||
// Operator calls have function call syntax. The `*this` parameter
|
||||
// is the first parameter.
|
||||
if (OpCall->getNumArgs() == 0 || OpCall->getArg(0) != Entry.E) {
|
||||
if (OpCall->getNumArgs() == 0 || OpCall->getArg(0) != Entry.E)
|
||||
return false;
|
||||
}
|
||||
const auto *const Method =
|
||||
dyn_cast_or_null<CXXMethodDecl>(OpCall->getDirectCallee());
|
||||
|
||||
@ -303,9 +300,8 @@ AST_MATCHER_P(DeclRefExpr, doesNotMutateObject, int, Indirections) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (Method->isConst() || Method->isStatic()) {
|
||||
if (Method->isConst() || Method->isStatic())
|
||||
continue;
|
||||
}
|
||||
if (isLikelyShallowConst(*Method)) {
|
||||
// We still have to check that the object is not modified through
|
||||
// the operator's return value (C).
|
||||
|
||||
@ -173,21 +173,17 @@ const Stmt *ExprSequence::getSequenceSuccessor(const Stmt *S) const {
|
||||
// Initializer list: Each initializer clause is sequenced after the
|
||||
// clauses that precede it.
|
||||
for (const InitListExpr *Form : getAllInitListForms(InitList)) {
|
||||
for (unsigned I = 1; I < Form->getNumInits(); ++I) {
|
||||
if (Form->getInit(I - 1) == S) {
|
||||
for (unsigned I = 1; I < Form->getNumInits(); ++I)
|
||||
if (Form->getInit(I - 1) == S)
|
||||
return Form->getInit(I);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (const auto *ConstructExpr = dyn_cast<CXXConstructExpr>(Parent)) {
|
||||
// Constructor arguments are sequenced if the constructor call is written
|
||||
// as list-initialization.
|
||||
if (ConstructExpr->isListInitialization()) {
|
||||
for (unsigned I = 1; I < ConstructExpr->getNumArgs(); ++I) {
|
||||
if (ConstructExpr->getArg(I - 1) == S) {
|
||||
for (unsigned I = 1; I < ConstructExpr->getNumArgs(); ++I)
|
||||
if (ConstructExpr->getArg(I - 1) == S)
|
||||
return ConstructExpr->getArg(I);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (const auto *Compound = dyn_cast<CompoundStmt>(Parent)) {
|
||||
// Compound statement: Each sub-statement is sequenced after the
|
||||
@ -260,10 +256,9 @@ const Stmt *ExprSequence::resolveSyntheticStmt(const Stmt *S) const {
|
||||
StmtToBlockMap::StmtToBlockMap(const CFG *TheCFG, ASTContext *TheContext)
|
||||
: Context(TheContext) {
|
||||
for (const auto *B : *TheCFG) {
|
||||
for (const auto &Elem : *B) {
|
||||
for (const auto &Elem : *B)
|
||||
if (std::optional<CFGStmt> S = Elem.getAs<CFGStmt>())
|
||||
Map[S->getStmt()] = B;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -243,7 +243,7 @@ bool areParensNeededForStatement(const Stmt &Node) {
|
||||
isa<BinaryConditionalOperator>(&Node))
|
||||
return true;
|
||||
|
||||
if (const auto *Op = dyn_cast<CXXOperatorCallExpr>(&Node)) {
|
||||
if (const auto *Op = dyn_cast<CXXOperatorCallExpr>(&Node))
|
||||
switch (Op->getOperator()) {
|
||||
case OO_PlusPlus:
|
||||
[[fallthrough]];
|
||||
@ -258,7 +258,6 @@ bool areParensNeededForStatement(const Stmt &Node) {
|
||||
default:
|
||||
return true;
|
||||
};
|
||||
}
|
||||
|
||||
if (isa<CStyleCastExpr>(&Node))
|
||||
return true;
|
||||
@ -301,9 +300,8 @@ std::string formatDereference(const Expr &ExprNode, const ASTContext &Context) {
|
||||
Text.consume_back("->");
|
||||
|
||||
// Add leading '*'.
|
||||
if (needParensAfterUnaryOperator(ExprNode)) {
|
||||
if (needParensAfterUnaryOperator(ExprNode))
|
||||
return (llvm::Twine("*(") + Text + ")").str();
|
||||
}
|
||||
return (llvm::Twine("*") + Text).str();
|
||||
}
|
||||
|
||||
|
||||
@ -793,10 +793,9 @@ void FormatStringConverter::applyFixes(DiagnosticBuilder &Diag,
|
||||
// Now we need to modify the ArgFix index too so that we fix the right
|
||||
// argument. We don't need to care about the width and precision indices
|
||||
// since they never need fixing.
|
||||
for (auto &ArgFix : ArgFixes) {
|
||||
for (auto &ArgFix : ArgFixes)
|
||||
if (ArgFix.ArgIndex == ValueArgIndex)
|
||||
ArgFix.ArgIndex = ValueArgIndex - ArgCount;
|
||||
}
|
||||
}
|
||||
|
||||
for (const auto &[ArgIndex, Replacement] : ArgFixes) {
|
||||
|
||||
@ -17,10 +17,9 @@ namespace utils {
|
||||
|
||||
static StringRef removeFirstSuffix(StringRef Str,
|
||||
ArrayRef<const char *> Suffixes) {
|
||||
for (const StringRef Suffix : Suffixes) {
|
||||
for (const StringRef Suffix : Suffixes)
|
||||
if (Str.consume_back(Suffix))
|
||||
return Str;
|
||||
}
|
||||
return Str;
|
||||
}
|
||||
|
||||
@ -45,9 +44,8 @@ static StringRef makeCanonicalName(StringRef Str,
|
||||
// Objective-C categories have a `+suffix` format, but should be grouped
|
||||
// with the file they are a category of.
|
||||
size_t StartIndex = Canonical.find_last_of('/');
|
||||
if (StartIndex == StringRef::npos) {
|
||||
if (StartIndex == StringRef::npos)
|
||||
StartIndex = 0;
|
||||
}
|
||||
return Canonical.substr(0, Canonical.find_first_of('+', StartIndex));
|
||||
}
|
||||
return removeFirstSuffix(
|
||||
@ -87,9 +85,8 @@ determineIncludeKind(StringRef CanonicalFile, StringRef IncludeFile,
|
||||
if (FileCopy.consume_front(Parts.first) &&
|
||||
FileCopy.consume_back(Parts.second)) {
|
||||
// Determine the kind of this inclusion.
|
||||
if (FileCopy == "/internal/" || FileCopy == "/proto/") {
|
||||
if (FileCopy == "/internal/" || FileCopy == "/proto/")
|
||||
return IncludeSorter::IK_MainTUInclude;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (Style == IncludeSorter::IS_Google_ObjC) {
|
||||
@ -108,12 +105,10 @@ static int compareHeaders(StringRef LHS, StringRef RHS,
|
||||
const std::pair<const char *, const char *> &Mismatch =
|
||||
std::mismatch(LHS.begin(), LHS.end(), RHS.begin(), RHS.end());
|
||||
if ((Mismatch.first != LHS.end()) && (Mismatch.second != RHS.end())) {
|
||||
if ((*Mismatch.first == '.') && (*Mismatch.second == '+')) {
|
||||
if ((*Mismatch.first == '.') && (*Mismatch.second == '+'))
|
||||
return -1;
|
||||
}
|
||||
if ((*Mismatch.first == '+') && (*Mismatch.second == '.')) {
|
||||
if ((*Mismatch.first == '+') && (*Mismatch.second == '.'))
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
return LHS.compare(RHS);
|
||||
@ -175,9 +170,8 @@ IncludeSorter::createIncludeInsertion(StringRef FileName, bool IsAngled) {
|
||||
const auto &Location = IncludeLocations[IncludeEntry][0];
|
||||
return FixItHint::CreateInsertion(Location.getBegin(), IncludeStmt);
|
||||
}
|
||||
if (FileName == IncludeEntry) {
|
||||
if (FileName == IncludeEntry)
|
||||
return std::nullopt;
|
||||
}
|
||||
}
|
||||
// FileName comes after all include entries in bucket, insert it after
|
||||
// last.
|
||||
@ -200,9 +194,8 @@ IncludeSorter::createIncludeInsertion(StringRef FileName, bool IsAngled) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (NonEmptyKind == IK_InvalidInclude) {
|
||||
if (NonEmptyKind == IK_InvalidInclude)
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
if (NonEmptyKind < IncludeKind) {
|
||||
// Create a block after.
|
||||
|
||||
@ -19,9 +19,8 @@ getPreviousTokenAndStart(SourceLocation Location, const SourceManager &SM,
|
||||
const std::optional<Token> Tok =
|
||||
Lexer::findPreviousToken(Location, SM, LangOpts, !SkipComments);
|
||||
|
||||
if (Tok.has_value()) {
|
||||
if (Tok.has_value())
|
||||
return {*Tok, Lexer::GetBeginningOfToken(Tok->getLocation(), SM, LangOpts)};
|
||||
}
|
||||
|
||||
Token Token;
|
||||
Token.setKind(tok::unknown);
|
||||
|
||||
@ -120,9 +120,8 @@ public:
|
||||
|
||||
private:
|
||||
MatchMode determineMatchMode(llvm::StringRef Regex) {
|
||||
if (Regex.starts_with(":") || Regex.starts_with("^:")) {
|
||||
if (Regex.starts_with(":") || Regex.starts_with("^:"))
|
||||
return MatchMode::MatchFullyQualified;
|
||||
}
|
||||
return Regex.contains(":") ? MatchMode::MatchQualified
|
||||
: MatchMode::MatchUnqualified;
|
||||
}
|
||||
|
||||
@ -84,9 +84,8 @@ std::string NamespaceAliaser::getNamespaceName(ASTContext &Context,
|
||||
const auto *Function = getSurroundingFunction(Context, Statement);
|
||||
auto FunctionAliases = AddedAliases.find(Function);
|
||||
if (FunctionAliases != AddedAliases.end()) {
|
||||
if (FunctionAliases->second.contains(Namespace)) {
|
||||
if (FunctionAliases->second.contains(Namespace))
|
||||
return FunctionAliases->second.find(Namespace)->getValue();
|
||||
}
|
||||
}
|
||||
return Namespace.str();
|
||||
}
|
||||
|
||||
@ -493,9 +493,8 @@ void RenamerClangTidyCheck::addUsage(const NamedDecl *Decl,
|
||||
Failure.Info = std::move(*MaybeFailure);
|
||||
|
||||
// Don't overwrite the failure status if it was already set.
|
||||
if (!Failure.shouldFix()) {
|
||||
if (!Failure.shouldFix())
|
||||
return;
|
||||
}
|
||||
const IdentifierTable &Idents = FailureDecl->getASTContext().Idents;
|
||||
auto CheckNewIdentifier = Idents.find(Failure.Info.Fixup);
|
||||
if (CheckNewIdentifier != Idents.end()) {
|
||||
|
||||
@ -113,9 +113,8 @@ bool isTriviallyDefaultConstructible(QualType Type, const ASTContext &Context) {
|
||||
if (CanonicalType->isScalarType() || CanonicalType->isVectorType())
|
||||
return true;
|
||||
|
||||
if (const auto *RD = CanonicalType->getAsRecordDecl()) {
|
||||
if (const auto *RD = CanonicalType->getAsRecordDecl())
|
||||
return recordIsTriviallyDefaultConstructible(*RD, Context);
|
||||
}
|
||||
|
||||
// No other types can match.
|
||||
return false;
|
||||
|
||||
@ -200,9 +200,8 @@ void UseRangesCheck::check(const MatchFinder::MatchResult &Result) {
|
||||
continue;
|
||||
Function = Value.get<FunctionDecl>();
|
||||
size_t Index = 0;
|
||||
if (NodeStr.getAsInteger(10, Index)) {
|
||||
if (NodeStr.getAsInteger(10, Index))
|
||||
llvm_unreachable("Unable to extract replacer index");
|
||||
}
|
||||
assert(Index < Replacers.size());
|
||||
Replacer = Replacers[Index].get();
|
||||
break;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user