[PATCH] D48728: [clang-format] Do not format raw string literals inside a recognized function with a non-recognized delimiter

Krasimir Georgiev via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Jun 28 10:03:37 PDT 2018


This revision was not accepted when it landed; it landed in state "Needs Review".
This revision was automatically updated to reflect the committed changes.
Closed by commit rL335876: [clang-format] Do not format raw string literals inside a recognized function… (authored by krasimir, committed by ).
Herald added a subscriber: llvm-commits.

Repository:
  rL LLVM

https://reviews.llvm.org/D48728

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


Index: cfe/trunk/unittests/Format/FormatTestRawStrings.cpp
===================================================================
--- cfe/trunk/unittests/Format/FormatTestRawStrings.cpp
+++ cfe/trunk/unittests/Format/FormatTestRawStrings.cpp
@@ -862,6 +862,32 @@
                     Style));
 }
 
+TEST_F(FormatTestRawStrings,
+       DoNotFormatUnrecognizedDelimitersInRecognizedFunctions) {
+  FormatStyle Style = getRawStringPbStyleWithColumns(60);
+  Style.RawStringFormats[0].EnclosingFunctions.push_back(
+      "EqualsProto");
+  // EqualsProto is a recognized function, but the Raw delimiter is
+  // unrecognized. Do not touch the string in this case, since it might be
+  // special.
+  expect_eq(R"test(
+void f() {
+  aaaaaaaaa(bbbbbbbbb, EqualsProto(R"Raw(
+item {
+  key: value
+}
+)Raw"));
+})test",
+            format(R"test(
+void f() {
+  aaaaaaaaa(bbbbbbbbb, EqualsProto(R"Raw(
+item {
+  key: value
+}
+)Raw"));
+})test",
+                   Style));
+}
 
 } // end namespace
 } // end namespace format
Index: cfe/trunk/lib/Format/ContinuationIndenter.cpp
===================================================================
--- cfe/trunk/lib/Format/ContinuationIndenter.cpp
+++ cfe/trunk/lib/Format/ContinuationIndenter.cpp
@@ -1648,7 +1648,7 @@
   if (!Delimiter)
     return None;
   auto RawStringStyle = RawStringFormats.getDelimiterStyle(*Delimiter);
-  if (!RawStringStyle)
+  if (!RawStringStyle && Delimiter->empty())
     RawStringStyle = RawStringFormats.getEnclosingFunctionStyle(
         getEnclosingFunctionName(Current));
   if (!RawStringStyle)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D48728.153342.patch
Type: text/x-patch
Size: 1580 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180628/9d768b80/attachment-0001.bin>


More information about the cfe-commits mailing list