diff options
-rw-r--r-- | clang/lib/Format/UnwrappedLineParser.cpp | 3 | ||||
-rw-r--r-- | clang/unittests/Format/FormatTestComments.cpp | 24 |
2 files changed, 18 insertions, 9 deletions
diff --git a/clang/lib/Format/UnwrappedLineParser.cpp b/clang/lib/Format/UnwrappedLineParser.cpp index bd049ef668b..9efb6812673 100644 --- a/clang/lib/Format/UnwrappedLineParser.cpp +++ b/clang/lib/Format/UnwrappedLineParser.cpp @@ -589,11 +589,12 @@ void UnwrappedLineParser::conditionalCompilationEnd() { } 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(); diff --git a/clang/unittests/Format/FormatTestComments.cpp b/clang/unittests/Format/FormatTestComments.cpp index cb1cefa47cf..df24abe2612 100644 --- a/clang/unittests/Format/FormatTestComments.cpp +++ b/clang/unittests/Format/FormatTestComments.cpp @@ -1683,14 +1683,6 @@ TEST_F(FormatTestComments, IgnoresIf0Contents) { "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" @@ -1809,6 +1801,22 @@ TEST_F(FormatTestComments, IgnoresIf0Contents) { "#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) { |