]> granicus.if.org Git - clang/commitdiff
Don't re-format raw string literal contents when formatting is disable
authorDaniel Jasper <djasper@google.com>
Mon, 12 Mar 2018 10:11:30 +0000 (10:11 +0000)
committerDaniel Jasper <djasper@google.com>
Mon, 12 Mar 2018 10:11:30 +0000 (10:11 +0000)
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

lib/Format/ContinuationIndenter.cpp
unittests/Format/FormatTestRawStrings.cpp

index d53cf808ddc35a7507668920b6dcecf43bd5ac00..000f82a0210c1047dac557dc2a6fa6b562ac74bb 100644 (file)
@@ -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
index daef6d7225ccdfaff3818b619e9e185d62faea93..85f0aab871023976058a5aab013e110a7523fe70 100644 (file)
@@ -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",