Skip to content

Commit 037657d

Browse files
authored
[clang-format] Correctly annotate kw_operator in using decls (#136545)
Fix #136541
1 parent 9efabbb commit 037657d

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

clang/lib/Format/TokenAnnotator.cpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -3977,8 +3977,10 @@ void TokenAnnotator::calculateFormattingInformation(AnnotatedLine &Line) const {
39773977
FormatToken *AfterLastAttribute = nullptr;
39783978
FormatToken *ClosingParen = nullptr;
39793979

3980-
for (auto *Tok = FirstNonComment ? FirstNonComment->Next : nullptr; Tok;
3981-
Tok = Tok->Next) {
3980+
for (auto *Tok = FirstNonComment && FirstNonComment->isNot(tok::kw_using)
3981+
? FirstNonComment->Next
3982+
: nullptr;
3983+
Tok; Tok = Tok->Next) {
39823984
if (Tok->is(TT_StartOfName))
39833985
SeenName = true;
39843986
if (Tok->Previous->EndsCppAttributeGroup)

clang/unittests/Format/TokenAnnotatorTest.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -1084,6 +1084,11 @@ TEST_F(TokenAnnotatorTest, UnderstandsOverloadedOperators) {
10841084
ASSERT_EQ(Tokens.size(), 11u) << Tokens;
10851085
EXPECT_TOKEN(Tokens[3], tok::identifier, TT_FunctionDeclarationName);
10861086
EXPECT_TOKEN(Tokens[7], tok::l_paren, TT_OverloadedOperatorLParen);
1087+
1088+
Tokens = annotate("using std::operator==;");
1089+
ASSERT_EQ(Tokens.size(), 7u) << Tokens;
1090+
// Not TT_FunctionDeclarationName.
1091+
EXPECT_TOKEN(Tokens[3], tok::kw_operator, TT_Unknown);
10871092
}
10881093

10891094
TEST_F(TokenAnnotatorTest, OverloadedOperatorInTemplate) {

0 commit comments

Comments
 (0)