clang-format: Fix infinite loop in macro special case.
If escaped newlines are aligned right
(FormatStyle.AlignEscapedNewlinesLeft == false), and a line contained
too many characters to fit into the column limit, this would result in
a (virtually) endless loop creating a negative number of spaces.
Instead, allow the escaped newlines to be pushed past the column limit
in this case.
This fixes llvm.org/PR16515.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@189459 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp
index f5afbd3..d80011b 100644
--- a/unittests/Format/FormatTest.cpp
+++ b/unittests/Format/FormatTest.cpp
@@ -1814,7 +1814,7 @@
verifyFormat("#define A( \\\n BB)", getLLVMStyleWithColumns(12));
verifyFormat("#define A( \\\n A, B)", getLLVMStyleWithColumns(12));
// FIXME: We never break before the macro name.
- verifyFormat("#define AA(\\\n B)", getLLVMStyleWithColumns(12));
+ verifyFormat("#define AA( \\\n B)", getLLVMStyleWithColumns(12));
verifyFormat("#define A A\n#define A A");
verifyFormat("#define A(X) A\n#define A A");
@@ -1887,9 +1887,9 @@
TEST_F(FormatTest, HashInMacroDefinition) {
verifyFormat("#define A \\\n b #c;", getLLVMStyleWithColumns(11));
- verifyFormat("#define A \\\n"
- " { \\\n"
- " f(#c);\\\n"
+ verifyFormat("#define A \\\n"
+ " { \\\n"
+ " f(#c); \\\n"
" }",
getLLVMStyleWithColumns(11));
@@ -4396,7 +4396,7 @@
EXPECT_EQ("/* */ /* */ /* */\n/* */ /* */ /* */",
format("/* *//* */ /* */\n/* *//* */ /* */"));
EXPECT_EQ("/* */ a /* */ b;", format(" /* */ a/* */ b;"));
- EXPECT_EQ("#define A /*123*/\\\n"
+ EXPECT_EQ("#define A /*123*/ \\\n"
" b\n"
"/* */\n"
"someCall(\n"