Index: clang/lib/Format/UnwrappedLineFormatter.cpp =================================================================== --- clang/lib/Format/UnwrappedLineFormatter.cpp +++ clang/lib/Format/UnwrappedLineFormatter.cpp @@ -1489,6 +1489,7 @@ // Insert or remove empty line after access specifiers. if (PreviousLine && PreviousLine->First->isAccessSpecifier() && + !RootToken.Finalized && (!PreviousLine->InPPDirective || !RootToken.HasUnescapedNewline)) { // EmptyLineBeforeAccessModifier is handling the case when two access // modifiers follow each other. Index: clang/unittests/Format/FormatTest.cpp =================================================================== --- clang/unittests/Format/FormatTest.cpp +++ clang/unittests/Format/FormatTest.cpp @@ -12857,6 +12857,39 @@ "};\n", Style); + verifyFormat("struct foo {\n" + "#ifdef FOO1\n" + "#else\n" + "private:\n" + "\n" + "#endif\n" + "};", + "struct foo {\n" + "#ifdef FOO1\n" + "#else\n" + "private:\n" + "\n" + "#endif\n" + "};", + Style); + + verifyFormat("struct foo {\n" + "#ifdef FOO2\n" + "#else\n" + "private:\n" + "\n" + "#endif\n" + "};", + "struct foo {\n" + "#ifdef FOO2\n" + "#else\n" + "private:\n" + "\n" + "\n" + "#endif\n" + "};", + Style); + Style.EmptyLineAfterAccessModifier = FormatStyle::ELAAMS_Always; verifyFormat("struct foo {\n" "private:\n"