Skip to content

Commit 19884d6

Browse files
committed
[clang-format] Don't skip PP lines if original line was a PP line when trying to merge lines
Fixes a crash introduced in D123737 where LastNonComment would be null. Reviewed By: curdeius Differential Revision: https://reviews.llvm.org/D124036
1 parent 945e022 commit 19884d6

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

clang/lib/Format/UnwrappedLineFormatter.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -307,9 +307,13 @@ class LineJoiner {
307307
// TODO: Use IndentTracker to avoid loop?
308308
// Find the last line with lower level.
309309
auto J = I - 1;
310-
for (; J != AnnotatedLines.begin(); --J)
311-
if (!(*J)->InPPDirective && (*J)->Level < TheLine->Level)
312-
break;
310+
if (!TheLine->InPPDirective) {
311+
for (; J != AnnotatedLines.begin(); --J) {
312+
if (!(*J)->InPPDirective && (*J)->Level < TheLine->Level)
313+
break;
314+
}
315+
}
316+
313317
if ((*J)->Level >= TheLine->Level)
314318
return false;
315319

clang/unittests/Format/FormatTest.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13393,6 +13393,12 @@ TEST_F(FormatTest, MergeHandlingInTheFaceOfPreprocessorDirectives) {
1339313393
" return 1; \\\n"
1339413394
" return 2;",
1339513395
ShortMergedIf);
13396+
13397+
verifyFormat("//\n"
13398+
"#define a \\\n"
13399+
" if \\\n"
13400+
" 0",
13401+
getChromiumStyle(FormatStyle::LK_Cpp));
1339613402
}
1339713403

1339813404
TEST_F(FormatTest, FormatStarDependingOnContext) {

0 commit comments

Comments
 (0)