r175533 - Correctly format macro with unfinished template declaration.

Daniel Jasper djasper at google.com
Tue Feb 19 09:14:39 PST 2013


Author: djasper
Date: Tue Feb 19 11:14:38 2013
New Revision: 175533

URL: http://llvm.org/viewvc/llvm-project?rev=175533&view=rev
Log:
Correctly format macro with unfinished template declaration.

We can now format:
  #define A template <typename T>

Before this created a segfault :-/.

Modified:
    cfe/trunk/lib/Format/TokenAnnotator.cpp
    cfe/trunk/unittests/Format/FormatTest.cpp

Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=175533&r1=175532&r2=175533&view=diff
==============================================================================
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Tue Feb 19 11:14:38 2013
@@ -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;

Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=175533&r1=175532&r2=175533&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Tue Feb 19 11:14:38 2013
@@ -378,12 +378,6 @@ TEST_F(FormatTest, FormatsSwitchStatemen
   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, EmptyLinesInMacroDefi
                    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}}"));
 }





More information about the cfe-commits mailing list