[PATCH] D134233: [clang-format] Wrap inserted braces only if preceded by comments
Owen Pan via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Sep 19 15:53:37 PDT 2022
owenpan created this revision.
owenpan added reviewers: MyDeveloperDay, HazardyKnusperkeks, curdeius.
owenpan added a project: clang-format.
Herald added a project: All.
owenpan requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
Fixes https://github.com/llvm/llvm-project/issues/57805.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D134233
Files:
clang/lib/Format/Format.cpp
clang/unittests/Format/FormatTest.cpp
Index: clang/unittests/Format/FormatTest.cpp
===================================================================
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -25388,6 +25388,12 @@
"} while (0);",
Style);
+ Style.RemoveBracesLLVM = true;
+ verifyFormat("if (a) //\n"
+ " return b;",
+ Style);
+ Style.RemoveBracesLLVM = false;
+
Style.ColumnLimit = 15;
verifyFormat("#define A \\\n"
Index: clang/lib/Format/Format.cpp
===================================================================
--- clang/lib/Format/Format.cpp
+++ clang/lib/Format/Format.cpp
@@ -1871,7 +1871,7 @@
std::string Brace;
if (Token->BraceCount < 0) {
assert(Token->BraceCount == -1);
- Brace = "\n{";
+ Brace = Token->is(tok::comment) ? "\n{" : "{";
} else {
Brace = '\n' + std::string(Token->BraceCount, '}');
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D134233.461395.patch
Type: text/x-patch
Size: 977 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220919/5b120e8b/attachment.bin>
More information about the cfe-commits
mailing list