]> granicus.if.org Git - clang/commitdiff
Fix r296605 so that stuff in #ifndef SWIG blocks is still formatted.
authorDaniel Jasper <djasper@google.com>
Wed, 1 Mar 2017 11:10:11 +0000 (11:10 +0000)
committerDaniel Jasper <djasper@google.com>
Wed, 1 Mar 2017 11:10:11 +0000 (11:10 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@296608 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Format/UnwrappedLineParser.cpp
unittests/Format/FormatTestComments.cpp

index bd049ef668b2ed6be797d9230133f4f4e78bf625..9efb6812673f2c74b84260db58d934319d4a18b6 100644 (file)
@@ -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();
index cb1cefa47cf63b0e248b73a9df4ae368bfbb8d8c..df24abe2612575373ba658cb73d99f7d030af273 100644 (file)
@@ -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) {