Skip to content

Commit ee64684

Browse files
committed
Revert "[clang-format] Correctly annotate */& in if condition with braced init (#109505)"
This reverts commit 98281da which caused a regression. Fixes #112176.
1 parent b9f0867 commit ee64684

File tree

2 files changed

+9
-21
lines changed

2 files changed

+9
-21
lines changed

clang/lib/Format/TokenAnnotator.cpp

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1175,26 +1175,19 @@ class AnnotatingParser {
11751175

11761176
ScopedContextCreator ContextCreator(*this, tok::l_brace, 1);
11771177
Contexts.back().ColonIsDictLiteral = true;
1178-
1179-
const auto *Prev = OpeningBrace.getPreviousNonComment();
1180-
1181-
if (OpeningBrace.is(BK_BracedInit)) {
1178+
if (OpeningBrace.is(BK_BracedInit))
11821179
Contexts.back().IsExpression = true;
1183-
if (Prev) {
1184-
for (auto *Tok = Prev->Previous; Tok && Tok->isPointerOrReference();
1185-
Tok = Tok->Previous) {
1186-
Tok->setFinalizedType(TT_PointerOrReference);
1187-
}
1188-
}
1189-
}
1190-
1191-
if (Style.isJavaScript() && Prev && Prev->is(TT_JsTypeColon))
1180+
if (Style.isJavaScript() && OpeningBrace.Previous &&
1181+
OpeningBrace.Previous->is(TT_JsTypeColon)) {
11921182
Contexts.back().IsExpression = false;
1193-
1183+
}
1184+
if (Style.isVerilog() &&
1185+
(!OpeningBrace.getPreviousNonComment() ||
1186+
OpeningBrace.getPreviousNonComment()->isNot(Keywords.kw_apostrophe))) {
1187+
Contexts.back().VerilogMayBeConcatenation = true;
1188+
}
11941189
if (Style.isTableGen())
11951190
Contexts.back().ColonIsDictLiteral = false;
1196-
else if (Style.isVerilog() && !(Prev && Prev->is(Keywords.kw_apostrophe)))
1197-
Contexts.back().VerilogMayBeConcatenation = true;
11981191

11991192
unsigned CommaCount = 0;
12001193
while (CurrentToken) {

clang/unittests/Format/TokenAnnotatorTest.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -308,11 +308,6 @@ TEST_F(TokenAnnotatorTest, UnderstandsUsesOfStarAndAmp) {
308308
EXPECT_TOKEN(Tokens[3], tok::star, TT_PointerOrReference);
309309
EXPECT_TOKEN(Tokens[4], tok::amp, TT_PointerOrReference);
310310

311-
Tokens = annotate("if (Foo *&foo{a})");
312-
ASSERT_EQ(Tokens.size(), 11u) << Tokens;
313-
EXPECT_TOKEN(Tokens[3], tok::star, TT_PointerOrReference);
314-
EXPECT_TOKEN(Tokens[4], tok::amp, TT_PointerOrReference);
315-
316311
FormatStyle Style = getLLVMStyle();
317312
Style.TypeNames.push_back("MYI");
318313
Tokens = annotate("if (MYI *p{nullptr})", Style);

0 commit comments

Comments
 (0)