]> granicus.if.org Git - clang/commitdiff
clang-format: Fix bug in escaped newline calculation.
authorDaniel Jasper <djasper@google.com>
Sun, 10 May 2015 08:00:25 +0000 (08:00 +0000)
committerDaniel Jasper <djasper@google.com>
Sun, 10 May 2015 08:00:25 +0000 (08:00 +0000)
This prevents clang-format from inadvertently joining stuff into macro
definitions as reported in llvm.org/PR23466.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@236944 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Format/Format.cpp
unittests/Format/FormatTest.cpp

index aa24891adc78b962c3b13547522703f9cde3b1f2..aec5bb4b59992792f1459863e9790e15331bca94 100644 (file)
@@ -1008,7 +1008,7 @@ private:
         // See whether there is an odd number of '\' before this.
         unsigned count = 0;
         for (; pos >= 0; --pos, ++count)
-          if (Text[count] != '\\')
+          if (Text[pos] != '\\')
             break;
         return count & 1;
       };
index 9d29a26848591380a67ebb1f9c709da3277ea075..6569badd0356e9d32d03a991b4e09af1b1174b5b 100644 (file)
@@ -2987,6 +2987,8 @@ TEST_F(FormatTest, EscapedNewlines) {
   EXPECT_EQ(
       "#define A \\\n  int i;  \\\n  int j;",
       format("#define A \\\nint i;\\\n  int j;", getLLVMStyleWithColumns(11)));
+  EXPECT_EQ(
+      "#define A\n\nint i;", format("#define A \\\n\n int i;"));
   EXPECT_EQ("template <class T> f();", format("\\\ntemplate <class T> f();"));
   EXPECT_EQ("/* \\  \\  \\\n*/", format("\\\n/* \\  \\  \\\n*/"));
   EXPECT_EQ("<a\n\\\\\n>", format("<a\n\\\\\n>"));