}
void UnwrappedLineParser::parsePPIf(bool IfDef) {
+ bool IfNDef = FormatTok->is(tok::pp_ifndef);
nextToken();
bool Unreachable = false;
if (!IfDef && (FormatTok->is(tok::kw_false) || FormatTok->TokenText == "0"))
Unreachable = true;
- if (IfDef && FormatTok->TokenText == "SWIG")
+ if (IfDef && !IfNDef && FormatTok->TokenText == "SWIG")
Unreachable = true;
conditionalCompilationStart(Unreachable);
parsePPUnknown();
"void f( ) { }\n"
"#endif\n"
"void g( ) { }\n"));
- EXPECT_EQ("#ifdef SWIG\n"
- "}{)(&*(^%%#%@! fsadj f;ldjs ,:;| <<<>>>][)(][\n"
- "#endif\n"
- "void f() {}",
- format("#ifdef SWIG\n"
- "}{)(&*(^%%#%@! fsadj f;ldjs ,:;| <<<>>>][)(][\n"
- "#endif\n"
- "void f( ) { }"));
EXPECT_EQ("enum E {\n"
" One,\n"
" Two,\n"
"#endif\n"
"Five\n"
"};"));
+
+ // Ignore stuff in SWIG-blocks.
+ EXPECT_EQ("#ifdef SWIG\n"
+ "}{)(&*(^%%#%@! fsadj f;ldjs ,:;| <<<>>>][)(][\n"
+ "#endif\n"
+ "void f() {}",
+ format("#ifdef SWIG\n"
+ "}{)(&*(^%%#%@! fsadj f;ldjs ,:;| <<<>>>][)(][\n"
+ "#endif\n"
+ "void f( ) { }"));
+ EXPECT_EQ("#ifndef SWIG\n"
+ "void f() {}\n"
+ "#endif",
+ format("#ifndef SWIG\n"
+ "void f( ) { }\n"
+ "#endif"));
}
TEST_F(FormatTestComments, DontCrashOnBlockComments) {