diff options
| author | Daniel Jasper <djasper@google.com> | 2013-02-19 17:14:38 +0000 |
|---|---|---|
| committer | Daniel Jasper <djasper@google.com> | 2013-02-19 17:14:38 +0000 |
| commit | 0047596cb0d3db50e8e8f0c9bbf7189a536ae722 (patch) | |
| tree | d4116225e99f864a5e34b33886c99b66a3723bb7 /clang | |
| parent | 2c197e09397ee071c678ba77c2451166264b55f7 (diff) | |
| download | bcm5719-llvm-0047596cb0d3db50e8e8f0c9bbf7189a536ae722.tar.gz bcm5719-llvm-0047596cb0d3db50e8e8f0c9bbf7189a536ae722.zip | |
Correctly format macro with unfinished template declaration.
We can now format:
#define A template <typename T>
Before this created a segfault :-/.
llvm-svn: 175533
Diffstat (limited to 'clang')
| -rw-r--r-- | clang/lib/Format/TokenAnnotator.cpp | 3 | ||||
| -rw-r--r-- | 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 bb2e04b66e8..d9368c36499 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 fb388ab7f97..3a1e9dce95a 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 <typename T>"); +} + TEST_F(FormatTest, IndentPreprocessorDirectivesAtZero) { EXPECT_EQ("{\n {\n#define A\n }\n}", format("{{\n#define A\n}}")); } |

