[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
Tue Sep 20 12:09:59 PDT 2022


This revision was automatically updated to reflect the committed changes.
Closed by commit rG6257832bf94f: [clang-format] Wrap inserted braces only if preceded by comments (authored by owenpan).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D134233/new/

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.461652.patch
Type: text/x-patch
Size: 977 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220920/a7d511f2/attachment.bin>


More information about the cfe-commits mailing list