Skip to content

Commit c280bed

Browse files
[clang-format] Fix annotating annotations after requires clause
Fixes #69325.
1 parent a6dabed commit c280bed

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

clang/lib/Format/TokenAnnotator.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2101,7 +2101,8 @@ class AnnotatingParser {
21012101
BeforeParen->isNot(TT_TypenameMacro) &&
21022102
BeforeParen->TokenText == BeforeParen->TokenText.upper() &&
21032103
(!BeforeParen->Previous ||
2104-
BeforeParen->Previous->ClosesTemplateDeclaration)) {
2104+
BeforeParen->Previous->ClosesTemplateDeclaration ||
2105+
BeforeParen->Previous->ClosesRequiresClause)) {
21052106
Current.setType(TT_FunctionAnnotationRParen);
21062107
}
21072108
}

clang/unittests/Format/TokenAnnotatorTest.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1376,6 +1376,20 @@ TEST_F(TokenAnnotatorTest, RequiresDoesNotChangeParsingOfTheRest) {
13761376
"}";
13771377
RequiresTokenCount = 9;
13781378
TestRequires(__LINE__);
1379+
1380+
BaseCode = "template<typename T>\n"
1381+
"ANNOTATE(\"S\"\n"
1382+
" \"S\")\n"
1383+
"void foo();";
1384+
ConstrainedCode = "template<typename T>\n"
1385+
" requires(true)\n"
1386+
"ANNOTATE(\"S\"\n"
1387+
" \"S\")\n"
1388+
"void foo();";
1389+
BaseTokenCount = 16;
1390+
RequiresTokenCount = 4;
1391+
PrefixTokenCount = 5;
1392+
TestRequires(__LINE__);
13791393
}
13801394

13811395
TEST_F(TokenAnnotatorTest, UnderstandsAsm) {

0 commit comments

Comments
 (0)