[PATCH] D99503: [clang-format] Inconsistent behavior regarding line break before access modifier
Max Sagebaum via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Apr 15 01:52:31 PDT 2021
Max_S updated this revision to Diff 337665.
Max_S added a comment.
Moved the test to their own section and fixed the formatting issues.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D99503/new/
https://reviews.llvm.org/D99503
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
@@ -9177,6 +9177,47 @@
" int j;\n"
"};\n",
Style);
+
+ FormatStyle NoEmptyLines = getLLVMStyle();
+ NoEmptyLines.MaxEmptyLinesToKeep = 0;
+ verifyFormat("struct foo {\n"
+ "private:\n"
+ " void f() {}\n"
+ "\n"
+ "private:\n"
+ " int i;\n"
+ "\n"
+ "public:\n"
+ "protected:\n"
+ " int j;\n"
+ "};\n",
+ NoEmptyLines);
+
+ NoEmptyLines.EmptyLineBeforeAccessModifier = FormatStyle::ELBAMS_Never;
+ verifyFormat("struct foo {\n"
+ "private:\n"
+ " void f() {}\n"
+ "private:\n"
+ " int i;\n"
+ "public:\n"
+ "protected:\n"
+ " int j;\n"
+ "};\n",
+ NoEmptyLines);
+
+ NoEmptyLines.EmptyLineBeforeAccessModifier = FormatStyle::ELBAMS_Always;
+ verifyFormat("struct foo {\n"
+ "private:\n"
+ " void f() {}\n"
+ "\n"
+ "private:\n"
+ " int i;\n"
+ "\n"
+ "public:\n"
+ "protected:\n"
+ " int j;\n"
+ "};\n",
+ NoEmptyLines);
}
TEST_F(FormatTest, FormatsArrays) {
Index: clang/lib/Format/UnwrappedLineFormatter.cpp
===================================================================
--- clang/lib/Format/UnwrappedLineFormatter.cpp
+++ clang/lib/Format/UnwrappedLineFormatter.cpp
@@ -1254,15 +1254,14 @@
if (PreviousLine && RootToken.isAccessSpecifier()) {
switch (Style.EmptyLineBeforeAccessModifier) {
case FormatStyle::ELBAMS_Never:
- if (RootToken.NewlinesBefore > 1)
+ if (Newlines > 1)
Newlines = 1;
break;
case FormatStyle::ELBAMS_Leave:
Newlines = std::max(RootToken.NewlinesBefore, 1u);
break;
case FormatStyle::ELBAMS_LogicalBlock:
- if (PreviousLine->Last->isOneOf(tok::semi, tok::r_brace) &&
- RootToken.NewlinesBefore <= 1)
+ if (PreviousLine->Last->isOneOf(tok::semi, tok::r_brace) && Newlines <= 1)
Newlines = 2;
break;
case FormatStyle::ELBAMS_Always: {
@@ -1271,8 +1270,7 @@
previousToken = PreviousLine->Last->getPreviousNonComment();
else
previousToken = PreviousLine->Last;
- if ((!previousToken || !previousToken->is(tok::l_brace)) &&
- RootToken.NewlinesBefore <= 1)
+ if ((!previousToken || !previousToken->is(tok::l_brace)) && Newlines <= 1)
Newlines = 2;
} break;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D99503.337665.patch
Type: text/x-patch
Size: 2850 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210415/4aaccc38/attachment.bin>
More information about the cfe-commits
mailing list