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

Daniel Jasper via cfe-commits cfe-commits at lists.llvm.org
Mon Mar 12 03:11:30 PDT 2018


Author: djasper
Date: Mon Mar 12 03:11:30 2018
New Revision: 327253

URL: http://llvm.org/viewvc/llvm-project?rev=327253&view=rev
Log:
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.

Modified:
    cfe/trunk/lib/Format/ContinuationIndenter.cpp
    cfe/trunk/unittests/Format/FormatTestRawStrings.cpp

Modified: cfe/trunk/lib/Format/ContinuationIndenter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/ContinuationIndenter.cpp?rev=327253&r1=327252&r2=327253&view=diff
==============================================================================
--- cfe/trunk/lib/Format/ContinuationIndenter.cpp (original)
+++ cfe/trunk/lib/Format/ContinuationIndenter.cpp Mon Mar 12 03:11:30 2018
@@ -1480,7 +1480,7 @@ unsigned ContinuationIndenter::handleEnd
   // 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

Modified: cfe/trunk/unittests/Format/FormatTestRawStrings.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTestRawStrings.cpp?rev=327253&r1=327252&r2=327253&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTestRawStrings.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTestRawStrings.cpp Mon Mar 12 03:11:30 2018
@@ -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",




More information about the cfe-commits mailing list