Skip to content

Commit 798f201

Browse files
authored
[clang-format] Don't format comments in SkipMacroDefinitionBody (#94425)
Fixes #94326.
1 parent 62c0eae commit 798f201

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

clang/lib/Format/UnwrappedLineParser.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1181,10 +1181,10 @@ void UnwrappedLineParser::parsePPDefine() {
11811181
Line->InMacroBody = true;
11821182

11831183
if (Style.SkipMacroDefinitionBody) {
1184-
do {
1184+
while (!eof()) {
11851185
FormatTok->Finalized = true;
1186-
nextToken();
1187-
} while (!eof());
1186+
FormatTok = Tokens->getNextToken();
1187+
}
11881188
addUnwrappedLine();
11891189
return;
11901190
}

clang/unittests/Format/FormatTest.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24879,7 +24879,7 @@ TEST_F(FormatTest, SkipMacroDefinitionBody) {
2487924879
Style);
2488024880

2488124881
// With comments.
24882-
verifyFormat("/* */ #define A a // a a", "/* */ # define A a // a a",
24882+
verifyFormat("/* */ #define A a // a a", "/* */ # define A a // a a",
2488324883
Style);
2488424884
verifyNoChange("/* */ #define A a // a a", Style);
2488524885

@@ -24891,6 +24891,15 @@ TEST_F(FormatTest, SkipMacroDefinitionBody) {
2489124891
"int aaa; // a",
2489224892
Style);
2489324893

24894+
verifyNoChange(
24895+
"#define MACRO_WITH_COMMENTS() \\\n"
24896+
" public: \\\n"
24897+
" /* Documentation parsed by Doxygen for the following method. */ \\\n"
24898+
" static MyType getClassTypeId(); \\\n"
24899+
" /** Normal comment for the following method. */ \\\n"
24900+
" virtual MyType getTypeId() const;",
24901+
Style);
24902+
2489424903
// multiline macro definitions
2489524904
verifyNoChange("#define A a\\\n"
2489624905
" A a \\\n "

0 commit comments

Comments
 (0)