[clang] [clang-format][NFC] Introduce isNoneOf (PR #161021)
via cfe-commits
cfe-commits at lists.llvm.org
Wed Oct 1 13:00:22 PDT 2025
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 origin/main HEAD --extensions cpp,h -- clang/lib/Format/ContinuationIndenter.cpp clang/lib/Format/Format.cpp clang/lib/Format/FormatToken.cpp clang/lib/Format/FormatToken.h clang/lib/Format/FormatTokenLexer.cpp clang/lib/Format/MacroExpander.cpp clang/lib/Format/NamespaceEndCommentsFixer.cpp clang/lib/Format/ObjCPropertyAttributeOrderFixer.cpp clang/lib/Format/QualifierAlignmentFixer.cpp clang/lib/Format/SortJavaScriptImports.cpp clang/lib/Format/TokenAnnotator.cpp clang/lib/Format/UnwrappedLineFormatter.cpp clang/lib/Format/UnwrappedLineParser.cpp clang/lib/Format/WhitespaceManager.cpp
``````````
:warning:
The reproduction instructions above might return results for more than one PR
in a stack if you are using a stacked PR workflow. You can limit the results by
changing `origin/main` to the base branch/commit you want to compare against.
:warning:
</details>
<details>
<summary>
View the diff from clang-format here.
</summary>
``````````diff
diff --git a/clang/lib/Format/ContinuationIndenter.cpp b/clang/lib/Format/ContinuationIndenter.cpp
index dfef76b96..cd4c1aaba 100644
--- a/clang/lib/Format/ContinuationIndenter.cpp
+++ b/clang/lib/Format/ContinuationIndenter.cpp
@@ -524,7 +524,7 @@ bool ContinuationIndenter::mustBreak(const LineState &State) {
(NewLineColumn == State.FirstIndent + Style.ContinuationIndentWidth ||
Previous.is(tok::comma) || Current.NestingLevel < 2) &&
Previous.isNoneOf(tok::kw_return, tok::lessless, tok::at,
- Keywords.kw_dollar) &&
+ Keywords.kw_dollar) &&
Previous.isNoneOf(TT_InlineASMColon, TT_ConditionalExpr) &&
nextIsMultilineString(State)) {
return true;
@@ -844,7 +844,7 @@ void ContinuationIndenter::addTokenOnCurrentLine(LineState &State, bool DryRun,
if (Tok.Previous->isIf())
return Style.AlignAfterOpenBracket == FormatStyle::BAS_AlwaysBreak;
return Tok.Previous->isNoneOf(TT_CastRParen, tok::kw_for, tok::kw_while,
- tok::kw_switch) &&
+ tok::kw_switch) &&
!(Style.isJavaScript() && Tok.Previous->is(Keywords.kw_await));
};
auto IsFunctionCallParen = [](const FormatToken &Tok) {
@@ -884,7 +884,7 @@ void ContinuationIndenter::addTokenOnCurrentLine(LineState &State, bool DryRun,
}
if (const auto *Previous = Tok.Previous;
!Previous || (Previous->isNoneOf(TT_FunctionDeclarationLParen,
- TT_LambdaDefinitionLParen) &&
+ TT_LambdaDefinitionLParen) &&
!IsFunctionCallParen(*Previous))) {
return true;
}
@@ -921,8 +921,8 @@ void ContinuationIndenter::addTokenOnCurrentLine(LineState &State, bool DryRun,
if (Style.AlignAfterOpenBracket != FormatStyle::BAS_DontAlign &&
!CurrentState.IsCSharpGenericTypeConstraint && Previous.opensScope() &&
Previous.isNoneOf(TT_ObjCMethodExpr, TT_RequiresClause,
- TT_TableGenDAGArgOpener,
- TT_TableGenDAGArgOpenerToBreak) &&
+ TT_TableGenDAGArgOpener,
+ TT_TableGenDAGArgOpenerToBreak) &&
!(Current.MacroParent && Previous.MacroParent) &&
(Current.isNot(TT_LineComment) ||
Previous.isOneOf(BK_BracedInit, TT_VerilogMultiLineListLParen)) &&
@@ -1735,7 +1735,7 @@ unsigned ContinuationIndenter::moveStateToNextToken(LineState &State,
if (Previous && (Previous->isOneOf(TT_BinaryOperator, TT_ConditionalExpr) ||
(Previous->isOneOf(tok::l_paren, tok::comma, tok::colon) &&
Previous->isNoneOf(TT_DictLiteral, TT_ObjCMethodExpr,
- TT_CtorInitializerColon)))) {
+ TT_CtorInitializerColon)))) {
CurrentState.NestedBlockInlined =
!Newline && hasNestedBlockInlined(Previous, Current, Style);
}
diff --git a/clang/lib/Format/FormatToken.h b/clang/lib/Format/FormatToken.h
index cb54645af..e4ddd610b 100644
--- a/clang/lib/Format/FormatToken.h
+++ b/clang/lib/Format/FormatToken.h
@@ -752,7 +752,7 @@ public:
bool isMemberAccess() const {
return isOneOf(tok::arrow, tok::period, tok::arrowstar) &&
isNoneOf(TT_DesignatedInitializerPeriod, TT_TrailingReturnArrow,
- TT_LambdaArrow, TT_LeadingJavaAnnotation);
+ TT_LambdaArrow, TT_LeadingJavaAnnotation);
}
bool isPointerOrReference() const {
diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp
index 2a8456448..59f81b361 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -1425,8 +1425,8 @@ private:
Scopes.back() == ST_Class)) {
Tok->setType(TT_BitFieldColon);
} else if (Contexts.size() == 1 &&
- Line.getFirstNonComment()->isNoneOf(
- tok::kw_enum, tok::kw_case, tok::kw_default) &&
+ Line.getFirstNonComment()->isNoneOf(tok::kw_enum, tok::kw_case,
+ tok::kw_default) &&
!Line.startsWith(tok::kw_typedef, tok::kw_enum)) {
if (Prev->isOneOf(tok::r_paren, tok::kw_noexcept) ||
Prev->ClosesRequiresClause) {
@@ -1562,12 +1562,11 @@ private:
if (Line.MustBeDeclaration && Contexts.size() == 1 &&
!Contexts.back().IsExpression && !Line.startsWith(TT_ObjCProperty) &&
!Line.startsWith(tok::l_paren) &&
- Tok->isNoneOf(TT_TypeDeclarationParen,
- TT_RequiresExpressionLParen)) {
+ Tok->isNoneOf(TT_TypeDeclarationParen, TT_RequiresExpressionLParen)) {
if (!Prev ||
(!Prev->isAttribute() &&
Prev->isNoneOf(TT_RequiresClause, TT_LeadingJavaAnnotation,
- TT_BinaryOperator))) {
+ TT_BinaryOperator))) {
Line.MightBeFunctionDecl = true;
Tok->MightBeFunctionDeclParen = true;
}
@@ -1730,8 +1729,7 @@ private:
// cond ? cond2 ? "A" : "B" : "C";
if (!Contexts.back().IsExpression && Line.MustBeDeclaration &&
(!Next || Next->isNoneOf(tok::identifier, tok::string_literal) ||
- !Next->Next ||
- Next->Next->isNoneOf(tok::colon, tok::question))) {
+ !Next->Next || Next->Next->isNoneOf(tok::colon, tok::question))) {
Tok->setType(TT_CSharpNullable);
break;
}
@@ -2233,7 +2231,7 @@ private:
if (Contexts.back().ContextKind == tok::less) {
assert(Current.Previous->Previous);
return Current.Previous->Previous->isNoneOf(tok::kw_typename,
- tok::kw_class);
+ tok::kw_class);
}
Tok = Tok->MatchingParen;
@@ -2432,8 +2430,7 @@ private:
Current.setType(TT_BinaryOperator);
} else if (Current.is(tok::arrow) && AutoFound &&
Line.MightBeFunctionDecl && Current.NestingLevel == 0 &&
- Current.Previous->isNoneOf(tok::kw_operator,
- tok::identifier)) {
+ Current.Previous->isNoneOf(tok::kw_operator, tok::identifier)) {
// not auto operator->() -> xxx;
Current.setType(TT_TrailingReturnArrow);
} else if (Current.is(tok::arrow) && Current.Previous &&
@@ -2573,8 +2570,8 @@ private:
tok::kw_requires) &&
Current.Previous &&
Current.Previous->isNoneOf(tok::equal, tok::at,
- TT_CtorInitializerComma,
- TT_CtorInitializerColon) &&
+ TT_CtorInitializerComma,
+ TT_CtorInitializerColon) &&
Line.MightBeFunctionDecl && Contexts.size() == 1) {
// Line.MightBeFunctionDecl can only be true after the parentheses of a
// function declaration have been found.
@@ -2784,7 +2781,7 @@ private:
// before the parentheses, this is unlikely to be a cast.
if (LeftOfParens->Tok.getIdentifierInfo() &&
LeftOfParens->isNoneOf(Keywords.kw_in, tok::kw_return, tok::kw_case,
- tok::kw_delete, tok::kw_throw)) {
+ tok::kw_delete, tok::kw_throw)) {
return false;
}
@@ -3744,7 +3741,7 @@ void TokenAnnotator::annotate(AnnotatedLine &Line) {
for (auto &Child : Line.Children) {
if (InRequiresExpression &&
Child->First->isNoneOf(tok::kw_typename, tok::kw_requires,
- TT_CompoundRequirementLBrace)) {
+ TT_CompoundRequirementLBrace)) {
Child->Type = LT_SimpleRequirement;
}
annotate(*Child);
@@ -4332,8 +4329,8 @@ unsigned TokenAnnotator::splitPenalty(const AnnotatedLine &Line,
if (Right.is(TT_LambdaLSquare) && Left.is(tok::equal))
return 35;
if (Right.isNoneOf(TT_ObjCMethodExpr, TT_LambdaLSquare,
- TT_ArrayInitializerLSquare,
- TT_DesignatedInitializerLSquare, TT_AttributeSquare)) {
+ TT_ArrayInitializerLSquare,
+ TT_DesignatedInitializerLSquare, TT_AttributeSquare)) {
return 500;
}
}
@@ -4812,8 +4809,8 @@ bool TokenAnnotator::spaceRequiredBetween(const AnnotatedLine &Line,
}
if (Right.is(tok::l_square) &&
Right.isNoneOf(TT_ObjCMethodExpr, TT_LambdaLSquare,
- TT_DesignatedInitializerLSquare,
- TT_StructuredBindingLSquare, TT_AttributeSquare) &&
+ TT_DesignatedInitializerLSquare,
+ TT_StructuredBindingLSquare, TT_AttributeSquare) &&
Left.isNoneOf(tok::numeric_constant, TT_DictLiteral) &&
!(Left.isNot(tok::r_square) && Style.SpaceBeforeSquareBrackets &&
Right.is(TT_ArraySubscriptLSquare))) {
@@ -5264,7 +5261,7 @@ bool TokenAnnotator::spaceRequiredBefore(const AnnotatedLine &Line,
return false;
if (Left.is(TT_TemplateCloser) &&
Right.isNoneOf(tok::equal, tok::l_brace, tok::comma, tok::l_square,
- Keywords.kw_implements, Keywords.kw_extends)) {
+ Keywords.kw_implements, Keywords.kw_extends)) {
// Type assertions ('<type>expr') are not followed by whitespace. Other
// locations that should have whitespace following are identified by the
// above set of follower tokens.
@@ -5558,8 +5555,8 @@ bool TokenAnnotator::spaceRequiredBefore(const AnnotatedLine &Line,
((Style.Standard < FormatStyle::LS_Cpp11) ||
ShouldAddSpacesInAngles())) ||
Left.isNoneOf(tok::l_paren, tok::r_paren, tok::l_square,
- tok::kw___super, TT_TemplateOpener,
- TT_TemplateCloser) ||
+ tok::kw___super, TT_TemplateOpener,
+ TT_TemplateCloser) ||
(Left.is(tok::l_paren) && Style.SpacesInParensOptions.Other);
}
if ((Left.is(TT_TemplateOpener)) != (Right.is(TT_TemplateCloser)))
@@ -6210,7 +6207,7 @@ bool TokenAnnotator::canBreakBefore(const AnnotatedLine &Line,
// Avoid to break after '(' in the cases that is in bang operators.
if (Right.is(tok::l_paren)) {
return Left.isNoneOf(TT_TableGenBangOperator, TT_TableGenCondOperator,
- TT_TemplateCloser);
+ TT_TemplateCloser);
}
// Avoid to break between the value and its suffix part.
if (Left.is(TT_TableGenValueSuffix))
@@ -6298,7 +6295,7 @@ bool TokenAnnotator::canBreakBefore(const AnnotatedLine &Line,
if (Right.is(tok::colon) &&
Right.isNoneOf(TT_CtorInitializerColon, TT_InlineASMColon,
- TT_BitFieldColon)) {
+ TT_BitFieldColon)) {
return false;
}
if (Left.is(tok::colon) && Left.isOneOf(TT_DictLiteral, TT_ObjCMethodExpr)) {
@@ -6381,8 +6378,7 @@ bool TokenAnnotator::canBreakBefore(const AnnotatedLine &Line,
}
if (Left.isOneOf(TT_TemplateCloser, TT_UnaryOperator, tok::kw_operator))
return false;
- if (Left.is(tok::equal) &&
- Right.isNoneOf(tok::kw_default, tok::kw_delete) &&
+ if (Left.is(tok::equal) && Right.isNoneOf(tok::kw_default, tok::kw_delete) &&
Line.Type == LT_VirtualFunctionDecl && Left.NestingLevel == 0) {
return false;
}
@@ -6410,7 +6406,7 @@ bool TokenAnnotator::canBreakBefore(const AnnotatedLine &Line,
// declaration.
if (Left.is(TT_TrailingAnnotation)) {
return Right.isNoneOf(tok::l_brace, tok::semi, tok::equal, tok::l_paren,
- tok::less, tok::coloncolon);
+ tok::less, tok::coloncolon);
}
if (Right.isAttribute())
diff --git a/clang/lib/Format/UnwrappedLineFormatter.cpp b/clang/lib/Format/UnwrappedLineFormatter.cpp
index 6e84af962..ac9c81d44 100644
--- a/clang/lib/Format/UnwrappedLineFormatter.cpp
+++ b/clang/lib/Format/UnwrappedLineFormatter.cpp
@@ -507,7 +507,7 @@ private:
!Style.BraceWrapping.SplitEmptyRecord);
} else if (TheLine->InPPDirective ||
TheLine->First->isNoneOf(tok::kw_class, tok::kw_enum,
- tok::kw_struct)) {
+ tok::kw_struct)) {
// Try to merge a block with left brace unwrapped that wasn't yet
// covered.
ShouldMerge = !Style.BraceWrapping.AfterFunction ||
diff --git a/clang/lib/Format/UnwrappedLineParser.cpp b/clang/lib/Format/UnwrappedLineParser.cpp
index 3136705ff..28797433e 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -405,8 +405,7 @@ bool UnwrappedLineParser::parseLevel(const FormatToken *OpeningBrace,
case tok::r_brace:
if (OpeningBrace) {
if (!Style.RemoveBracesLLVM || Line->InPPDirective ||
- OpeningBrace->isNoneOf(TT_ControlStatementLBrace,
- TT_ElseLBrace)) {
+ OpeningBrace->isNoneOf(TT_ControlStatementLBrace, TT_ElseLBrace)) {
return false;
}
if (FormatTok->isNot(tok::r_brace) || StatementCount != 1 || HasLabel ||
@@ -1234,22 +1233,22 @@ void UnwrappedLineParser::parsePPUnknown() {
static bool tokenCanStartNewLine(const FormatToken &Tok) {
// Semicolon can be a null-statement, l_square can be a start of a macro or
// a C++11 attribute, but this doesn't seem to be common.
- return Tok.isNoneOf(
- tok::semi, tok::l_brace,
- // Tokens that can only be used as binary operators and a
- // part of overloaded operator names.
- tok::period, tok::periodstar, tok::arrow, tok::arrowstar, tok::less,
- tok::greater, tok::slash, tok::percent, tok::lessless,
- tok::greatergreater, tok::equal, tok::plusequal, tok::minusequal,
- tok::starequal, tok::slashequal, tok::percentequal, tok::ampequal,
- tok::pipeequal, tok::caretequal, tok::greatergreaterequal,
- tok::lesslessequal,
- // Colon is used in labels, base class lists, initializer lists,
- // range-based for loops, ternary operator, but should never be the first
- // token in an unwrapped line.
- tok::colon,
- // 'noexcept' is a trailing annotation.
- tok::kw_noexcept);
+ return Tok.isNoneOf(tok::semi, tok::l_brace,
+ // Tokens that can only be used as binary operators and a
+ // part of overloaded operator names.
+ tok::period, tok::periodstar, tok::arrow, tok::arrowstar,
+ tok::less, tok::greater, tok::slash, tok::percent,
+ tok::lessless, tok::greatergreater, tok::equal,
+ tok::plusequal, tok::minusequal, tok::starequal,
+ tok::slashequal, tok::percentequal, tok::ampequal,
+ tok::pipeequal, tok::caretequal, tok::greatergreaterequal,
+ tok::lesslessequal,
+ // Colon is used in labels, base class lists, initializer
+ // lists, range-based for loops, ternary operator, but
+ // should never be the first token in an unwrapped line.
+ tok::colon,
+ // 'noexcept' is a trailing annotation.
+ tok::kw_noexcept);
}
static bool mustBeJSIdent(const AdditionalKeywords &Keywords,
@@ -3110,8 +3109,8 @@ void UnwrappedLineParser::parseTryCatch() {
if (FormatTok->is(tok::at))
nextToken();
if (FormatTok->isNoneOf(tok::kw_catch, Keywords.kw___except,
- tok::kw___finally, tok::objc_catch,
- tok::objc_finally) &&
+ tok::kw___finally, tok::objc_catch,
+ tok::objc_finally) &&
!((Style.isJava() || Style.isJavaScript()) &&
FormatTok->is(Keywords.kw_finally))) {
break;
@@ -4888,7 +4887,7 @@ void UnwrappedLineParser::readToken(int LevelDifference) {
if ((Style.isVerilog() && !Keywords.isVerilogPPDirective(*Next)) ||
(Style.isTableGen() &&
Next->isNoneOf(tok::kw_else, tok::pp_define, tok::pp_ifdef,
- tok::pp_ifndef, tok::pp_endif))) {
+ tok::pp_ifndef, tok::pp_endif))) {
break;
}
distributeComments(Comments, FormatTok);
diff --git a/clang/lib/Format/WhitespaceManager.cpp b/clang/lib/Format/WhitespaceManager.cpp
index ee668fbcc..54f366fc0 100644
--- a/clang/lib/Format/WhitespaceManager.cpp
+++ b/clang/lib/Format/WhitespaceManager.cpp
@@ -463,7 +463,7 @@ AlignTokenSequence(const FormatStyle &Style, unsigned Start, unsigned End,
Style.ReferenceAlignment == FormatStyle::RAS_Right) &&
CurrentChange.Spaces != 0 &&
CurrentChange.Tok->isNoneOf(tok::equal, tok::r_paren,
- TT_TemplateCloser)) {
+ TT_TemplateCloser)) {
const bool ReferenceNotRightAligned =
Style.ReferenceAlignment != FormatStyle::RAS_Right &&
Style.ReferenceAlignment != FormatStyle::RAS_Pointer;
``````````
</details>
https://github.com/llvm/llvm-project/pull/161021
More information about the cfe-commits
mailing list