Skip to content

Commit 182e8b7

Browse files
owencatstellar
authored andcommitted
[clang-format] Correctly annotate kw_operator in using decls (#136545)
Fix #136541 (cherry picked from commit 037657d)
1 parent 425d1aa commit 182e8b7

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

clang/lib/Format/TokenAnnotator.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3961,8 +3961,10 @@ void TokenAnnotator::calculateFormattingInformation(AnnotatedLine &Line) const {
39613961
FormatToken *AfterLastAttribute = nullptr;
39623962
FormatToken *ClosingParen = nullptr;
39633963

3964-
for (auto *Tok = FirstNonComment ? FirstNonComment->Next : nullptr; Tok;
3965-
Tok = Tok->Next) {
3964+
for (auto *Tok = FirstNonComment && FirstNonComment->isNot(tok::kw_using)
3965+
? FirstNonComment->Next
3966+
: nullptr;
3967+
Tok; Tok = Tok->Next) {
39663968
if (Tok->is(TT_StartOfName))
39673969
SeenName = true;
39683970
if (Tok->Previous->EndsCppAttributeGroup)

clang/unittests/Format/TokenAnnotatorTest.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1073,6 +1073,11 @@ TEST_F(TokenAnnotatorTest, UnderstandsOverloadedOperators) {
10731073
ASSERT_EQ(Tokens.size(), 11u) << Tokens;
10741074
EXPECT_TOKEN(Tokens[3], tok::identifier, TT_FunctionDeclarationName);
10751075
EXPECT_TOKEN(Tokens[7], tok::l_paren, TT_OverloadedOperatorLParen);
1076+
1077+
Tokens = annotate("using std::operator==;");
1078+
ASSERT_EQ(Tokens.size(), 7u) << Tokens;
1079+
// Not TT_FunctionDeclarationName.
1080+
EXPECT_TOKEN(Tokens[3], tok::kw_operator, TT_Unknown);
10761081
}
10771082

10781083
TEST_F(TokenAnnotatorTest, OverloadedOperatorInTemplate) {

0 commit comments

Comments
 (0)