r236944 - clang-format: Fix bug in escaped newline calculation.
Daniel Jasper
djasper at google.com
Sun May 10 01:00:25 PDT 2015
Author: djasper
Date: Sun May 10 03:00:25 2015
New Revision: 236944
URL: http://llvm.org/viewvc/llvm-project?rev=236944&view=rev
Log:
clang-format: Fix bug in escaped newline calculation.
This prevents clang-format from inadvertently joining stuff into macro
definitions as reported in llvm.org/PR23466.
Modified:
cfe/trunk/lib/Format/Format.cpp
cfe/trunk/unittests/Format/FormatTest.cpp
Modified: cfe/trunk/lib/Format/Format.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/Format.cpp?rev=236944&r1=236943&r2=236944&view=diff
==============================================================================
--- cfe/trunk/lib/Format/Format.cpp (original)
+++ cfe/trunk/lib/Format/Format.cpp Sun May 10 03:00:25 2015
@@ -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;
};
Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=236944&r1=236943&r2=236944&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Sun May 10 03:00:25 2015
@@ -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>"));
More information about the cfe-commits
mailing list