Răsfoiți Sursa

Don't re-format raw string literal contents when formatting is disable

Not entirely sure this is the best place to put this check, but it fixes
the immediate issue.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@327253 91177308-0d34-0410-b5e6-96231b3b80d8
Daniel Jasper 7 ani în urmă
părinte
comite
295d429ca1

+ 1 - 1
lib/Format/ContinuationIndenter.cpp

@@ -1480,7 +1480,7 @@ unsigned ContinuationIndenter::handleEndOfLine(const FormatToken &Current,
   // Compute the raw string style to use in case this is a raw string literal
   // that can be reformatted.
   auto RawStringStyle = getRawStringStyle(Current, State);
-  if (RawStringStyle) {
+  if (RawStringStyle && !Current.Finalized) {
     Penalty = reformatRawStringLiteral(Current, State, *RawStringStyle, DryRun);
   } else if (Current.IsMultiline && Current.isNot(TT_BlockComment)) {
     // Don't break multi-line tokens other than block comments and raw string

+ 14 - 0
unittests/Format/FormatTestRawStrings.cpp

@@ -164,6 +164,20 @@ t = R"pb(item:1)pb";)test",
                    getRawStringPbStyleWithColumns(40)));
 }
 
+TEST_F(FormatTestRawStrings, RespectsClangFormatOff) {
+  expect_eq(R"test(
+// clang-format off
+s = R"pb(item:      1)pb";
+// clang-format on
+t = R"pb(item: 1)pb";)test",
+            format(R"test(
+// clang-format off
+s = R"pb(item:      1)pb";
+// clang-format on
+t = R"pb(item:      1)pb";)test",
+                   getRawStringPbStyleWithColumns(40)));
+}
+
 TEST_F(FormatTestRawStrings, ReformatsShortRawStringsOnSingleLine) {
   expect_eq(
       R"test(P p = TP(R"pb()pb");)test",