Correctly format macro with unfinished template declaration.
authorDaniel Jasper <djasper@google.com>
Tue, 19 Feb 2013 17:14:38 +0000 (17:14 +0000)
committerDaniel Jasper <djasper@google.com>
Tue, 19 Feb 2013 17:14:38 +0000 (17:14 +0000)
We can now format:
  #define A template <typename T>

Before this created a segfault :-/.

llvm-svn: 175533

clang/lib/Format/TokenAnnotator.cpp
clang/unittests/Format/FormatTest.cpp

index bb2e04b..d9368c3 100644 (file)
@@ -293,7 +293,8 @@ private:
       next();
       if (!parseAngle())
         return false;
-      CurrentToken->Parent->ClosesTemplateDeclaration = true;
+      if (CurrentToken != NULL)
+        CurrentToken->Parent->ClosesTemplateDeclaration = true;
       return true;
     }
     return false;
index fb388ab..3a1e9dc 100644 (file)
@@ -378,12 +378,6 @@ TEST_F(FormatTest, FormatsSwitchStatement) {
   verifyFormat("switch (test)\n"
                "  ;");
 
-  // FIXME: Improve formatting of case labels in macros.
-  verifyFormat("#define SOMECASES  \\\n"
-               "case 1:            \\\n"
-               "  case 2\n",
-               getLLVMStyleWithColumns(20));
-
   verifyGoogleFormat("switch (x) {\n"
                      "  case 1:\n"
                      "    f();\n"
@@ -935,6 +929,16 @@ TEST_F(FormatTest, EmptyLinesInMacroDefinitions) {
                    getLLVMStyleWithColumns(11)));
 }
 
+TEST_F(FormatTest, MacroDefinitionsWithIncompleteCode) {
+  // FIXME: Improve formatting of case labels in macros.
+  verifyFormat("#define SOMECASES  \\\n"
+               "case 1:            \\\n"
+               "  case 2\n",
+               getLLVMStyleWithColumns(20));
+
+  verifyFormat("#define A template <typename T>");
+}
+
 TEST_F(FormatTest, IndentPreprocessorDirectivesAtZero) {
   EXPECT_EQ("{\n  {\n#define A\n  }\n}", format("{{\n#define A\n}}"));
 }