Skip to content

Commit

Permalink
[clang-format] Fix annotating annotations after requires clause
Browse files Browse the repository at this point in the history
Fixes #69325.
  • Loading branch information
HazardyKnusperkeks committed Oct 31, 2023
1 parent a6dabed commit c280bed
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
3 changes: 2 additions & 1 deletion clang/lib/Format/TokenAnnotator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2101,7 +2101,8 @@ class AnnotatingParser {
BeforeParen->isNot(TT_TypenameMacro) &&
BeforeParen->TokenText == BeforeParen->TokenText.upper() &&
(!BeforeParen->Previous ||
BeforeParen->Previous->ClosesTemplateDeclaration)) {
BeforeParen->Previous->ClosesTemplateDeclaration ||
BeforeParen->Previous->ClosesRequiresClause)) {
Current.setType(TT_FunctionAnnotationRParen);
}
}
Expand Down
14 changes: 14 additions & 0 deletions clang/unittests/Format/TokenAnnotatorTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1376,6 +1376,20 @@ TEST_F(TokenAnnotatorTest, RequiresDoesNotChangeParsingOfTheRest) {
"}";
RequiresTokenCount = 9;
TestRequires(__LINE__);

BaseCode = "template<typename T>\n"
"ANNOTATE(\"S\"\n"
" \"S\")\n"
"void foo();";
ConstrainedCode = "template<typename T>\n"
" requires(true)\n"
"ANNOTATE(\"S\"\n"
" \"S\")\n"
"void foo();";
BaseTokenCount = 16;
RequiresTokenCount = 4;
PrefixTokenCount = 5;
TestRequires(__LINE__);
}

TEST_F(TokenAnnotatorTest, UnderstandsAsm) {
Expand Down

0 comments on commit c280bed

Please sign in to comment.