From 89a0daa0ec1fbc43489e3bb9e9648c816258f00f Mon Sep 17 00:00:00 2001 From: Daniel Jasper Date: Tue, 12 Feb 2013 20:17:17 +0000 Subject: [PATCH] Fix crash for incomplete labels in macros. Still the formatting can be improved, but at least we don't assert any more. This happened when trying to format lib/Sema/SemaType.cpp. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@175003 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Format/UnwrappedLineParser.cpp | 4 ++-- unittests/Format/FormatTest.cpp | 6 ++++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/Format/UnwrappedLineParser.cpp b/lib/Format/UnwrappedLineParser.cpp index 922671600d..28522a3e32 100644 --- a/lib/Format/UnwrappedLineParser.cpp +++ b/lib/Format/UnwrappedLineParser.cpp @@ -565,8 +565,8 @@ void UnwrappedLineParser::parseDoWhile() { } void UnwrappedLineParser::parseLabel() { - // FIXME: remove all asserts. - assert(FormatTok.Tok.is(tok::colon) && "':' expected"); + if (FormatTok.Tok.isNot(tok::colon)) + return; nextToken(); unsigned OldLineLevel = Line->Level; if (Line->Level > 0) diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index f1cef2a03d..f28bc88444 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -353,6 +353,12 @@ 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" -- 2.40.0