[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:00:59 PDT 2018


krasimir created this revision.
Herald added a subscriber: cfe-commits.

This stops clang-format from touching raw string contents with unrecognized delimiters inside recognized functions.
Unrecognized delimiters signal that the string might be special.


Repository:
  rC Clang

https://reviews.llvm.org/D48728

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


Index: unittests/Format/FormatTestRawStrings.cpp
===================================================================
--- unittests/Format/FormatTestRawStrings.cpp
+++ 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: lib/Format/ContinuationIndenter.cpp
===================================================================
--- lib/Format/ContinuationIndenter.cpp
+++ 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.153339.patch
Type: text/x-patch
Size: 1520 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180628/bde481ef/attachment.bin>


More information about the cfe-commits mailing list