diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp index a457ced9f8868..4a7378c24cda5 100644 --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/lib/Format/TokenAnnotator.cpp @@ -3544,7 +3544,7 @@ void TokenAnnotator::calculateFormattingInformation(AnnotatedLine &Line) const { } } } - } else if (Current->SpacesRequiredBefore == 0 && + } else if (!Current->Finalized && Current->SpacesRequiredBefore == 0 && spaceRequiredBefore(Line, *Current)) { Current->SpacesRequiredBefore = 1; } diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index 0a87cfc4f1d6a..d5711782a23ef 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -26459,6 +26459,25 @@ TEST_F(FormatTest, AllowBreakBeforeNoexceptSpecifier) { Style); } +TEST_F(FormatTest, PPBranchesInBracedInit) { + verifyFormat("A a_{kFlag1,\n" + "#if BUILD_FLAG\n" + " kFlag2,\n" + "#else\n" + " kFlag3,\n" + "#endif\n" + " kFlag4};", + "A a_{\n" + " kFlag1,\n" + "#if BUILD_FLAG\n" + " kFlag2,\n" + "#else\n" + " kFlag3,\n" + "#endif\n" + " kFlag4\n" + "};"); +} + } // namespace } // namespace test } // namespace format