Skip to content

Commit a369a59

Browse files
authored
[clang-format] Fix a bug in formating #define A x: (#73220)
Fixed #70789.
1 parent 3bebf3b commit a369a59

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

clang/lib/Format/UnwrappedLineParser.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1171,6 +1171,12 @@ void UnwrappedLineParser::parsePPDefine() {
11711171
assert((int)Line->PPLevel >= 0);
11721172
Line->InMacroBody = true;
11731173

1174+
if (FormatTok->is(tok::identifier) &&
1175+
Tokens->peekNextToken()->is(tok::colon)) {
1176+
nextToken();
1177+
nextToken();
1178+
}
1179+
11741180
// Errors during a preprocessor directive can only affect the layout of the
11751181
// preprocessor directive, and thus we ignore them. An alternative approach
11761182
// would be to use the same approach we use on the file level (no

clang/unittests/Format/FormatTest.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1863,6 +1863,8 @@ TEST_F(FormatTest, UnderstandsMacros) {
18631863
verifyFormat("MACRO(something##something)");
18641864
verifyFormat("MACRO(return##something)");
18651865
verifyFormat("MACRO(co_return##something)");
1866+
1867+
verifyFormat("#define A x:");
18661868
}
18671869

18681870
TEST_F(FormatTest, ShortBlocksInMacrosDontMergeWithCodeAfterMacro) {

0 commit comments

Comments
 (0)