From 0047596cb0d3db50e8e8f0c9bbf7189a536ae722 Mon Sep 17 00:00:00 2001 From: Daniel Jasper Date: Tue, 19 Feb 2013 17:14:38 +0000 Subject: [PATCH] Correctly format macro with unfinished template declaration. We can now format: #define A template Before this created a segfault :-/. llvm-svn: 175533 --- clang/lib/Format/TokenAnnotator.cpp | 3 ++- clang/unittests/Format/FormatTest.cpp | 16 ++++++++++------ 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp index bb2e04b..d9368c3 100644 --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/lib/Format/TokenAnnotator.cpp @@ -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; diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index fb388ab..3a1e9dc 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -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 "); +} + TEST_F(FormatTest, IndentPreprocessorDirectivesAtZero) { EXPECT_EQ("{\n {\n#define A\n }\n}", format("{{\n#define A\n}}")); } -- 2.7.4