Skip to content

Commit f8fb158

Browse files
committed
[clang-format] Merge short inline function in macro definition body
Fix #62356
1 parent 6a1d3ea commit f8fb158

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
@@ -15086,6 +15086,13 @@ TEST_F(FormatTest, PullInlineFunctionDefinitionsIntoSingleLine) {
1508615086
"};",
1508715087
MergeInlineOnly);
1508815088

15089+
MergeInlineOnly.AlignEscapedNewlines = FormatStyle::ENAS_Left;
15090+
verifyFormat("#define Foo \\\n"
15091+
" struct S { \\\n"
15092+
" void foo() { return; } \\\n"
15093+
" }",
15094+
MergeInlineOnly);
15095+
1508915096
// Also verify behavior when BraceWrapping.AfterFunction = true
1509015097
MergeInlineOnly.BreakBeforeBraces = FormatStyle::BS_Custom;
1509115098
MergeInlineOnly.BraceWrapping.AfterFunction = true;

0 commit comments

Comments
 (0)