penagos created this revision.
penagos requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D120188

Files:
  clang/lib/Format/BreakableToken.cpp
  clang/unittests/Format/FormatTestComments.cpp


Index: clang/unittests/Format/FormatTestComments.cpp
===================================================================
--- clang/unittests/Format/FormatTestComments.cpp
+++ clang/unittests/Format/FormatTestComments.cpp
@@ -91,6 +91,12 @@
                "// line 2\n"
                "void f() {}\n");
 
+  EXPECT_EQ("// comment\n"
+            "// clang-format on\n",
+            format("//comment\n"
+                   "// clang-format on\n",
+                   getLLVMStyleWithColumns(20)));
+
   verifyFormat("void f() {\n"
                "  // Doesn't do anything\n"
                "}");
Index: clang/lib/Format/BreakableToken.cpp
===================================================================
--- clang/lib/Format/BreakableToken.cpp
+++ clang/lib/Format/BreakableToken.cpp
@@ -816,9 +816,10 @@
         assert(Lines[i].size() > IndentPrefix.size());
         const auto FirstNonSpace = Lines[i][IndentPrefix.size()];
         const auto AllowsSpaceChange =
-            SpacesInPrefix != 0 ||
-            (!NoSpaceBeforeFirstCommentChar() ||
-             (FirstNonSpace == '}' && FirstLineSpaceChange != 0));
+            (!LineTok || !switchesFormatting(*LineTok)) &&
+            (SpacesInPrefix != 0 ||
+             (!NoSpaceBeforeFirstCommentChar() ||
+              (FirstNonSpace == '}' && FirstLineSpaceChange != 0)));
 
         if (PrefixSpaceChange[i] > 0 && AllowsSpaceChange) {
           Prefix[i] = IndentPrefix.str();


Index: clang/unittests/Format/FormatTestComments.cpp
===================================================================
--- clang/unittests/Format/FormatTestComments.cpp
+++ clang/unittests/Format/FormatTestComments.cpp
@@ -91,6 +91,12 @@
                "// line 2\n"
                "void f() {}\n");
 
+  EXPECT_EQ("// comment\n"
+            "// clang-format on\n",
+            format("//comment\n"
+                   "// clang-format on\n",
+                   getLLVMStyleWithColumns(20)));
+
   verifyFormat("void f() {\n"
                "  // Doesn't do anything\n"
                "}");
Index: clang/lib/Format/BreakableToken.cpp
===================================================================
--- clang/lib/Format/BreakableToken.cpp
+++ clang/lib/Format/BreakableToken.cpp
@@ -816,9 +816,10 @@
         assert(Lines[i].size() > IndentPrefix.size());
         const auto FirstNonSpace = Lines[i][IndentPrefix.size()];
         const auto AllowsSpaceChange =
-            SpacesInPrefix != 0 ||
-            (!NoSpaceBeforeFirstCommentChar() ||
-             (FirstNonSpace == '}' && FirstLineSpaceChange != 0));
+            (!LineTok || !switchesFormatting(*LineTok)) &&
+            (SpacesInPrefix != 0 ||
+             (!NoSpaceBeforeFirstCommentChar() ||
+              (FirstNonSpace == '}' && FirstLineSpaceChange != 0)));
 
         if (PrefixSpaceChange[i] > 0 && AllowsSpaceChange) {
           Prefix[i] = IndentPrefix.str();
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to