From: Daniel Jasper Date: Sun, 10 May 2015 08:00:25 +0000 (+0000) Subject: clang-format: Fix bug in escaped newline calculation. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=9fb893e047ef9de217c3a6263ec0d66684f0cced;p=clang 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. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@236944 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Format/Format.cpp b/lib/Format/Format.cpp index aa24891adc..aec5bb4b59 100644 --- a/lib/Format/Format.cpp +++ b/lib/Format/Format.cpp @@ -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; }; diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index 9d29a26848..6569badd03 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -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 f();", format("\\\ntemplate f();")); EXPECT_EQ("/* \\ \\ \\\n*/", format("\\\n/* \\ \\ \\\n*/")); EXPECT_EQ("", format(""));