Skip to content

Commit

Permalink
[clang-format] Fix a bug in AnnotatingParser::rParenEndsCast() (llvm#…
Browse files Browse the repository at this point in the history
  • Loading branch information
owenca authored Jan 27, 2024
1 parent ff05c30 commit f826f55
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
2 changes: 2 additions & 0 deletions clang/lib/Format/TokenAnnotator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2488,6 +2488,8 @@ class AnnotatingParser {
(Tok.Next->Next->is(tok::numeric_constant) || Line.InPPDirective)) {
return false;
}
if (Line.InPPDirective && Tok.Next->is(tok::minus))
return false;
// Search for unexpected tokens.
for (FormatToken *Prev = Tok.Previous; Prev != Tok.MatchingParen;
Prev = Prev->Previous) {
Expand Down
5 changes: 5 additions & 0 deletions clang/unittests/Format/TokenAnnotatorTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -611,6 +611,11 @@ TEST_F(TokenAnnotatorTest, UnderstandsCasts) {
EXPECT_TOKEN(Tokens[13], tok::r_paren, TT_Unknown);
EXPECT_TOKEN(Tokens[14], tok::star, TT_BinaryOperator);

Tokens = annotate("#define foo(i) ((i) - bar)");
ASSERT_EQ(Tokens.size(), 14u) << Tokens;
EXPECT_TOKEN(Tokens[9], tok::r_paren, TT_Unknown);
EXPECT_TOKEN(Tokens[10], tok::minus, TT_BinaryOperator);

Tokens = annotate("return (Foo) & 10;");
ASSERT_EQ(Tokens.size(), 8u) << Tokens;
EXPECT_TOKEN(Tokens[3], tok::r_paren, TT_Unknown);
Expand Down

0 comments on commit f826f55

Please sign in to comment.