MyDeveloperDay created this revision. MyDeveloperDay added a reviewer: owenpan. MyDeveloperDay added projects: clang, clang-format. Herald added a project: All. Herald added reviewers: rymiel, HazardyKnusperkeks. MyDeveloperDay requested review of this revision.
Propose a new solution to D151954: [clang-format] Fix overlapping whitespace replacements before PPDirective <https://reviews.llvm.org/D151954> That was reverted as part of D152473: [clang-format] Add test case for issue 63170 <https://reviews.llvm.org/D152473> Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D152804 Files: clang/lib/Format/UnwrappedLineFormatter.cpp clang/unittests/Format/FormatTest.cpp 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" 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" 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.
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits