diff options
author | Owen Pan <owenpiano@gmail.com> | 2025-03-25 08:19:43 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-03-25 08:19:43 -0700 |
commit | 2497945a95bd6e66120476892816c90e42a592fc (patch) | |
tree | ec8c04cfde00e1ff4e7cc4bb90edf36f6674a9e4 /clang/lib/Format/UnwrappedLineParser.cpp | |
parent | 629ff2d7ba382cc9a584658d94a81818a06c34f2 (diff) | |
download | llvm-2497945a95bd6e66120476892816c90e42a592fc.zip llvm-2497945a95bd6e66120476892816c90e42a592fc.tar.gz llvm-2497945a95bd6e66120476892816c90e42a592fc.tar.bz2 |
[clang-format] Correctly annotate requires clause in `&& requires(` (#132882)
Fix #132334
Diffstat (limited to 'clang/lib/Format/UnwrappedLineParser.cpp')
-rw-r--r-- | clang/lib/Format/UnwrappedLineParser.cpp | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/clang/lib/Format/UnwrappedLineParser.cpp b/clang/lib/Format/UnwrappedLineParser.cpp index a6e0596..f7712be 100644 --- a/clang/lib/Format/UnwrappedLineParser.cpp +++ b/clang/lib/Format/UnwrappedLineParser.cpp @@ -1708,6 +1708,7 @@ void UnwrappedLineParser::parseStructuralElement( break; } + bool SeenEqual = false; for (const bool InRequiresExpression = OpeningBrace && OpeningBrace->isOneOf(TT_RequiresExpressionLBrace, TT_CompoundRequirementLBrace); @@ -1782,7 +1783,7 @@ void UnwrappedLineParser::parseStructuralElement( break; case tok::kw_requires: { if (IsCpp) { - bool ParsedClause = parseRequires(); + bool ParsedClause = parseRequires(SeenEqual); if (ParsedClause) return; } else { @@ -2062,6 +2063,7 @@ void UnwrappedLineParser::parseStructuralElement( break; } + SeenEqual = true; nextToken(); if (FormatTok->is(tok::l_brace)) { // Block kind should probably be set to BK_BracedInit for any language. @@ -3416,7 +3418,7 @@ void UnwrappedLineParser::parseAccessSpecifier() { /// \brief Parses a requires, decides if it is a clause or an expression. /// \pre The current token has to be the requires keyword. /// \returns true if it parsed a clause. -bool UnwrappedLineParser::parseRequires() { +bool UnwrappedLineParser::parseRequires(bool SeenEqual) { assert(FormatTok->is(tok::kw_requires) && "'requires' expected"); auto RequiresToken = FormatTok; @@ -3472,7 +3474,7 @@ bool UnwrappedLineParser::parseRequires() { // We check the one token before that for a const: // void member(...) const && requires (C<T> ... auto PrevPrev = PreviousNonComment->getPreviousNonComment(); - if (PrevPrev && PrevPrev->is(tok::kw_const)) { + if ((PrevPrev && PrevPrev->is(tok::kw_const)) || !SeenEqual) { parseRequiresClause(RequiresToken); return true; } |