Skip to content

Commit 6da2acf

Browse files
authored
[clang-format] Merge short inline function in macro definition body (#140366)
Fix #62356
1 parent 8231182 commit 6da2acf

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

clang/lib/Format/UnwrappedLineFormatter.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -314,8 +314,8 @@ class LineJoiner {
314314
const AnnotatedLine *Line = nullptr;
315315
for (auto J = I - 1; J >= AnnotatedLines.begin(); --J) {
316316
assert(*J);
317-
if ((*J)->InPPDirective || (*J)->isComment() ||
318-
(*J)->Level > TheLine->Level) {
317+
if (((*J)->InPPDirective && !(*J)->InMacroBody) ||
318+
(*J)->isComment() || (*J)->Level > TheLine->Level) {
319319
continue;
320320
}
321321
if ((*J)->Level < TheLine->Level ||

clang/unittests/Format/FormatTest.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15093,6 +15093,13 @@ TEST_F(FormatTest, PullInlineFunctionDefinitionsIntoSingleLine) {
1509315093
"};",
1509415094
MergeInlineOnly);
1509515095

15096+
MergeInlineOnly.AlignEscapedNewlines = FormatStyle::ENAS_Left;
15097+
verifyFormat("#define Foo \\\n"
15098+
" struct S { \\\n"
15099+
" void foo() { return; } \\\n"
15100+
" }",
15101+
MergeInlineOnly);
15102+
1509615103
// Also verify behavior when BraceWrapping.AfterFunction = true
1509715104
MergeInlineOnly.BreakBeforeBraces = FormatStyle::BS_Custom;
1509815105
MergeInlineOnly.BraceWrapping.AfterFunction = true;

0 commit comments

Comments
 (0)