Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 7e7a906

Browse filesBrowse files
committed
Revert "[clang-format] Fix a bug in annotating * in #defines (#99433)"
This reverts commit ce1a874. Closes #100304.
1 parent 8e43acb commit 7e7a906
Copy full SHA for 7e7a906

File tree

Expand file treeCollapse file tree

2 files changed

+5
-34
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+5
-34
lines changed

‎clang/lib/Format/TokenAnnotator.cpp

Copy file name to clipboardExpand all lines: clang/lib/Format/TokenAnnotator.cpp
+5-14Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,10 @@ class AnnotatingParser {
372372
OpeningParen.Previous->is(tok::kw__Generic)) {
373373
Contexts.back().ContextType = Context::C11GenericSelection;
374374
Contexts.back().IsExpression = true;
375+
} else if (Line.InPPDirective &&
376+
(!OpeningParen.Previous ||
377+
OpeningParen.Previous->isNot(tok::identifier))) {
378+
Contexts.back().IsExpression = true;
375379
} else if (Contexts[Contexts.size() - 2].CaretFound) {
376380
// This is the parameter list of an ObjC block.
377381
Contexts.back().IsExpression = false;
@@ -384,20 +388,7 @@ class AnnotatingParser {
384388
OpeningParen.Previous->MatchingParen->isOneOf(
385389
TT_ObjCBlockLParen, TT_FunctionTypeLParen)) {
386390
Contexts.back().IsExpression = false;
387-
} else if (Line.InPPDirective) {
388-
auto IsExpr = [&OpeningParen] {
389-
const auto *Tok = OpeningParen.Previous;
390-
if (!Tok || Tok->isNot(tok::identifier))
391-
return true;
392-
Tok = Tok->Previous;
393-
while (Tok && Tok->endsSequence(tok::coloncolon, tok::identifier)) {
394-
assert(Tok->Previous);
395-
Tok = Tok->Previous->Previous;
396-
}
397-
return !Tok || !Tok->Tok.getIdentifierInfo();
398-
};
399-
Contexts.back().IsExpression = IsExpr();
400-
} else if (!Line.MustBeDeclaration) {
391+
} else if (!Line.MustBeDeclaration && !Line.InPPDirective) {
401392
bool IsForOrCatch =
402393
OpeningParen.Previous &&
403394
OpeningParen.Previous->isOneOf(tok::kw_for, tok::kw_catch);

‎clang/unittests/Format/TokenAnnotatorTest.cpp

Copy file name to clipboardExpand all lines: clang/unittests/Format/TokenAnnotatorTest.cpp
-20Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -75,26 +75,6 @@ TEST_F(TokenAnnotatorTest, UnderstandsUsesOfStarAndAmp) {
7575
EXPECT_TOKEN(Tokens[10], tok::r_paren, TT_TypeDeclarationParen);
7676
EXPECT_TOKEN(Tokens[11], tok::star, TT_PointerOrReference);
7777

78-
Tokens = annotate("#define FOO bar(a * b)");
79-
ASSERT_EQ(Tokens.size(), 10u) << Tokens;
80-
EXPECT_TOKEN(Tokens[6], tok::star, TT_BinaryOperator);
81-
82-
Tokens = annotate("#define FOO foo.bar(a & b)");
83-
ASSERT_EQ(Tokens.size(), 12u) << Tokens;
84-
EXPECT_TOKEN(Tokens[8], tok::amp, TT_BinaryOperator);
85-
86-
Tokens = annotate("#define FOO foo::bar(a && b)");
87-
ASSERT_EQ(Tokens.size(), 12u) << Tokens;
88-
EXPECT_TOKEN(Tokens[8], tok::ampamp, TT_BinaryOperator);
89-
90-
Tokens = annotate("#define FOO foo bar(a *b)");
91-
ASSERT_EQ(Tokens.size(), 11u) << Tokens;
92-
EXPECT_TOKEN(Tokens[7], tok::star, TT_PointerOrReference);
93-
94-
Tokens = annotate("#define FOO void foo::bar(a &b)");
95-
ASSERT_EQ(Tokens.size(), 13u) << Tokens;
96-
EXPECT_TOKEN(Tokens[9], tok::amp, TT_PointerOrReference);
97-
9878
Tokens = annotate("void f() {\n"
9979
" while (p < a && *p == 'a')\n"
10080
" p++;\n"

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.