Fixes PR14811: Crash when formatting some macros
A preprocessor directive cannot be started while we're parsing one.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@171635 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp
index d5c7978..89fe71c 100644
--- a/unittests/Format/FormatTest.cpp
+++ b/unittests/Format/FormatTest.cpp
@@ -458,6 +458,14 @@
EXPECT_EQ("int x,\n#define A\ny;", format("int x,\n#define A\ny;"));
}
+TEST_F(FormatTest, HashInMacroDefinition) {
+ verifyFormat("#define A \\\n b #c;", getLLVMStyleWithColumns(11));
+ verifyFormat("#define A \\\n"
+ " { \\\n"
+ " f(#c);\\\n"
+ " }", getLLVMStyleWithColumns(11));
+}
+
// FIXME: write test for unbalanced braces in macros...
// FIXME: test { { #include "a.h" } }
// FIXME: test # in the middle of a statement without \n before it