diff --git a/clang/lib/Format/UnwrappedLineFormatter.cpp b/clang/lib/Format/UnwrappedLineFormatter.cpp --- a/clang/lib/Format/UnwrappedLineFormatter.cpp +++ b/clang/lib/Format/UnwrappedLineFormatter.cpp @@ -308,7 +308,8 @@ // Find the last line with lower level. auto J = I - 1; for (; J != AnnotatedLines.begin(); --J) - if (!(*J)->InPPDirective && (*J)->Level < TheLine->Level) + if ((TheLine->InPPDirective || !(*J)->InPPDirective) && + (*J)->Level < TheLine->Level) break; if ((*J)->Level >= TheLine->Level) return false; diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -13393,6 +13393,12 @@ " return 1; \\\n" " return 2;", ShortMergedIf); + + verifyFormat("//\n" + "#define a \\\n" + " if \\\n" + " 0", + getChromiumStyle(FormatStyle::LK_Cpp)); } TEST_F(FormatTest, FormatStarDependingOnContext) {