[PATCH] D152804: [clang-format] Propose a new solution to - Fix overlapping replacements before PPDirectives
MyDeveloperDay via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Jun 13 05:32:45 PDT 2023
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.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D152804.530869.patch
Type: text/x-patch
Size: 1818 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230613/9d667072/attachment-0001.bin>
More information about the cfe-commits
mailing list