This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGf00f2b3e8d40: [clang-format] Fix a bug in removing braces
for the LLVM style (authored by owenpan).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D132805/new/
https://reviews.llvm.org/D132805
Files:
clang/lib/Format/UnwrappedLineParser.cpp
clang/unittests/Format/FormatTest.cpp
Index: clang/unittests/Format/FormatTest.cpp
===================================================================
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -25815,6 +25815,14 @@
"}",
Style);
+ verifyFormat("if (a) // comment\n"
+ " b = 1;",
+ "if (a) // comment\n"
+ "{\n"
+ " b = 1;\n"
+ "}",
+ Style);
+
verifyFormat("if (a) {\n"
"Label:\n"
"}",
Index: clang/lib/Format/UnwrappedLineParser.cpp
===================================================================
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -815,6 +815,10 @@
auto Length = LastToken->TotalLength;
if (OpeningBrace) {
assert(OpeningBrace != Tokens.front().Tok);
+ if (auto Prev = OpeningBrace->Previous;
+ Prev && Prev->TotalLength + ColumnLimit == OpeningBrace->TotalLength) {
+ Length -= ColumnLimit;
+ }
Length -= OpeningBrace->TokenText.size() + 1;
}
Index: clang/unittests/Format/FormatTest.cpp
===================================================================
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -25815,6 +25815,14 @@
"}",
Style);
+ verifyFormat("if (a) // comment\n"
+ " b = 1;",
+ "if (a) // comment\n"
+ "{\n"
+ " b = 1;\n"
+ "}",
+ Style);
+
verifyFormat("if (a) {\n"
"Label:\n"
"}",
Index: clang/lib/Format/UnwrappedLineParser.cpp
===================================================================
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -815,6 +815,10 @@
auto Length = LastToken->TotalLength;
if (OpeningBrace) {
assert(OpeningBrace != Tokens.front().Tok);
+ if (auto Prev = OpeningBrace->Previous;
+ Prev && Prev->TotalLength + ColumnLimit == OpeningBrace->TotalLength) {
+ Length -= ColumnLimit;
+ }
Length -= OpeningBrace->TokenText.size() + 1;
}
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits