Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion clang/lib/Format/TokenAnnotator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3112,7 +3112,7 @@ class AnnotatingParser {

// It's more likely that & represents operator& than an uninitialized
// reference.
if (Tok.is(tok::amp) && PrevToken && PrevToken->Tok.isAnyIdentifier() &&
if (Tok.is(tok::amp) && PrevToken->Tok.isAnyIdentifier() &&
IsChainedOperatorAmpOrMember(PrevToken->getPreviousNonComment()) &&
NextToken && NextToken->Tok.isAnyIdentifier()) {
if (auto NextNext = NextToken->getNextNonComment();
Expand All @@ -3122,6 +3122,9 @@ class AnnotatingParser {
}
}

if (PrevToken->isTypeName(LangOpts))
return TT_PointerOrReference;

if (Line.Type == LT_SimpleRequirement ||
(!Scopes.empty() && Scopes.back() == ST_CompoundRequirement)) {
return TT_BinaryOperator;
Expand Down
4 changes: 4 additions & 0 deletions clang/unittests/Format/TokenAnnotatorTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,10 @@ TEST_F(TokenAnnotatorTest, UnderstandsUsesOfStarAndAmp) {
EXPECT_TOKEN(Tokens[20], tok::l_brace, TT_CompoundRequirementLBrace);
EXPECT_TOKEN(Tokens[22], tok::star, TT_BinaryOperator);

Tokens = annotate("bool foo = requires { static_cast<int &&>(1); };");
ASSERT_EQ(Tokens.size(), 17u) << Tokens;
EXPECT_TOKEN(Tokens[8], tok::ampamp, TT_PointerOrReference);

Tokens = annotate("return s.operator int *();");
ASSERT_EQ(Tokens.size(), 10u) << Tokens;
// Not TT_FunctionDeclarationName.
Expand Down
Loading