Fixes PR14811: Crash when formatting some macros

A preprocessor directive cannot be started while we're parsing one.

llvm-svn: 171635
This commit is contained in:
Manuel Klimek 2013-01-05 21:34:55 +00:00
parent 219c7d9f64
commit 09e0797953
2 changed files with 9 additions and 1 deletions

View File

@ -469,7 +469,7 @@ void UnwrappedLineParser::nextToken() {
void UnwrappedLineParser::readToken() {
FormatTok = Tokens->getNextToken();
while (FormatTok.Tok.is(tok::hash)) {
while (!Line.InPPDirective && FormatTok.Tok.is(tok::hash)) {
// FIXME: This is incorrect - the correct way is to create a
// data structure that will construct the parts around the preprocessor
// directive as a structured \c UnwrappedLine.

View File

@ -458,6 +458,14 @@ TEST_F(FormatTest, MacroDefinitionInsideStatement) {
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