Skip to content

Commit

Permalink
[clang-format] Fix misannotation of && before noexcept (#65526)
Browse files Browse the repository at this point in the history
When we are in an expression, it has to be a binary operator and not
pointer or reference.
  • Loading branch information
HazardyKnusperkeks committed Sep 7, 2023
1 parent 5dce748 commit 4f7086c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
5 changes: 3 additions & 2 deletions clang/lib/Format/TokenAnnotator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2535,8 +2535,9 @@ class AnnotatingParser {
return TT_BinaryOperator;

if (!NextToken ||
NextToken->isOneOf(tok::arrow, tok::equal, tok::kw_noexcept, tok::comma,
tok::r_paren, TT_RequiresClause) ||
NextToken->isOneOf(tok::arrow, tok::equal, tok::comma, tok::r_paren,
TT_RequiresClause) ||
(NextToken->is(tok::kw_noexcept) && !IsExpression) ||
NextToken->canBePointerOrReferenceQualifier() ||
(NextToken->is(tok::l_brace) && !NextToken->getNextNonComment())) {
return TT_PointerOrReference;
Expand Down
7 changes: 7 additions & 0 deletions clang/unittests/Format/TokenAnnotatorTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,13 @@ TEST_F(TokenAnnotatorTest, UnderstandsUsesOfStarAndAmp) {
ASSERT_EQ(Tokens.size(), 19u) << Tokens;
EXPECT_TOKEN(Tokens[5], tok::ampamp, TT_BinaryOperator);

Tokens =
annotate("auto foo() noexcept(noexcept(bar()) && "
"trait<std::decay_t<decltype(bar())>> && noexcept(baz())) {}");
EXPECT_EQ(Tokens.size(), 38u) << Tokens;
EXPECT_TOKEN(Tokens[12], tok::ampamp, TT_BinaryOperator);
EXPECT_TOKEN(Tokens[27], tok::ampamp, TT_BinaryOperator);

FormatStyle Style = getLLVMStyle();
Style.TypeNames.push_back("MYI");
Tokens = annotate("if (MYI *p{nullptr})", Style);
Expand Down

0 comments on commit 4f7086c

Please sign in to comment.