Hi djasper,

http://llvm-reviews.chandlerc.com/D1640

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

Index: lib/Format/ContinuationIndenter.cpp
===================================================================
--- lib/Format/ContinuationIndenter.cpp
+++ lib/Format/ContinuationIndenter.cpp
@@ -651,6 +651,17 @@
     if (Current.IsUnterminatedLiteral)
       return 0;
 
+    // FIXME: Split the string and add _T() around each segment to work around 
a
+    // Visual C++ bug, which doesn't handle L"xxx" "yyy" as per 
[lex.string]p13:
+    // "If one string literal has no encoding-prefix, it is treated as a string
+    // literal of the same encoding-prefix as the other operand."
+    // More context here: http://llvm.org/PR17122
+    if (Current.Previous && Current.Previous->is(tok::l_paren) &&
+        Current.Previous->Previous &&
+        Current.Previous->Previous->TokenText == "_T" && Current.Next &&
+        Current.Next->is(tok::r_paren))
+      return 0;
+
     Token.reset(new BreakableStringLiteral(
         Current, StartColumn, State.Line->InPPDirective, Encoding, Style));
   } else if (Current.Type == TT_BlockComment && Current.isTrailingComment()) {
Index: unittests/Format/FormatTest.cpp
===================================================================
--- unittests/Format/FormatTest.cpp
+++ unittests/Format/FormatTest.cpp
@@ -5450,6 +5450,20 @@
       format("#define A \"some text other\";", AlignLeft));
 }
 
+TEST_F(FormatTest, BreaksStringLiteralsWithin_TMacro) {
+  // FIXME: Implement breaking strings withing _T() macro like this:
+  //EXPECT_EQ("_T(\"aaaaaaaaaaaaa\")\n"
+  //          "_T(\"aaaaaaaaaaaaa\")\n"
+  //          "_T(\"aaaaaaaaaaaaa\")\n"
+  //          "_T(\"a\")",
+  //          format("_T(\"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\")",
+  //                 getLLVMStyleWithColumns(20)));
+
+  EXPECT_EQ("_T(\"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\")",
+            format("_T(\"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\")",
+                   getLLVMStyleWithColumns(20)));
+}
+
 TEST_F(FormatTest, DontSplitStringLiteralsWithEscapedNewlines) {
   EXPECT_EQ(
       "aaaaaaaaaaa = \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\\\n"
Index: lib/Format/ContinuationIndenter.cpp
===================================================================
--- lib/Format/ContinuationIndenter.cpp
+++ lib/Format/ContinuationIndenter.cpp
@@ -651,6 +651,17 @@
     if (Current.IsUnterminatedLiteral)
       return 0;
 
+    // FIXME: Split the string and add _T() around each segment to work around a
+    // Visual C++ bug, which doesn't handle L"xxx" "yyy" as per [lex.string]p13:
+    // "If one string literal has no encoding-prefix, it is treated as a string
+    // literal of the same encoding-prefix as the other operand."
+    // More context here: http://llvm.org/PR17122
+    if (Current.Previous && Current.Previous->is(tok::l_paren) &&
+        Current.Previous->Previous &&
+        Current.Previous->Previous->TokenText == "_T" && Current.Next &&
+        Current.Next->is(tok::r_paren))
+      return 0;
+
     Token.reset(new BreakableStringLiteral(
         Current, StartColumn, State.Line->InPPDirective, Encoding, Style));
   } else if (Current.Type == TT_BlockComment && Current.isTrailingComment()) {
Index: unittests/Format/FormatTest.cpp
===================================================================
--- unittests/Format/FormatTest.cpp
+++ unittests/Format/FormatTest.cpp
@@ -5450,6 +5450,20 @@
       format("#define A \"some text other\";", AlignLeft));
 }
 
+TEST_F(FormatTest, BreaksStringLiteralsWithin_TMacro) {
+  // FIXME: Implement breaking strings withing _T() macro like this:
+  //EXPECT_EQ("_T(\"aaaaaaaaaaaaa\")\n"
+  //          "_T(\"aaaaaaaaaaaaa\")\n"
+  //          "_T(\"aaaaaaaaaaaaa\")\n"
+  //          "_T(\"a\")",
+  //          format("_T(\"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\")",
+  //                 getLLVMStyleWithColumns(20)));
+
+  EXPECT_EQ("_T(\"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\")",
+            format("_T(\"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\")",
+                   getLLVMStyleWithColumns(20)));
+}
+
 TEST_F(FormatTest, DontSplitStringLiteralsWithEscapedNewlines) {
   EXPECT_EQ(
       "aaaaaaaaaaa = \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\\\n"
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits

Reply via email to