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, '}');
         }


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, '}');
         }
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to