From 291f936351573780b30c7b80d54721f9d3471b53 Mon Sep 17 00:00:00 2001 From: Daniel Jasper Date: Wed, 20 Mar 2013 15:58:10 +0000 Subject: [PATCH] Remove assertion that can be triggered on bad input. clang-format can't do anything useful, so it should leave the remainder of the line unchanged, but it should not assert/segfault. llvm-svn: 177530 --- clang/lib/Format/Format.cpp | 3 +-- clang/unittests/Format/FormatTest.cpp | 5 ++++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp index b1005b5..b4cbfec 100644 --- a/clang/lib/Format/Format.cpp +++ b/clang/lib/Format/Format.cpp @@ -601,9 +601,8 @@ private: unsigned addTokenToState(bool Newline, bool DryRun, LineState &State) { const AnnotatedToken &Current = *State.NextToken; const AnnotatedToken &Previous = *State.NextToken->Parent; - assert(State.Stack.size()); - if (Current.Type == TT_ImplicitStringLiteral) { + if (State.Stack.size() == 0 || Current.Type == TT_ImplicitStringLiteral) { State.Column += State.NextToken->FormatTok.WhiteSpaceLength + State.NextToken->FormatTok.TokenLength; if (State.NextToken->Children.empty()) diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index 2a3d66d..0edb191 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -2413,7 +2413,10 @@ TEST_F(FormatTest, IncorrectAccessSpecifier) { "B { int x; }"); } -TEST_F(FormatTest, IncorrectCodeUnbalancedBraces) { verifyFormat("{"); } +TEST_F(FormatTest, IncorrectCodeUnbalancedBraces) { + verifyFormat("{"); + verifyFormat("#})"); +} TEST_F(FormatTest, IncorrectCodeDoNoWhile) { verifyFormat("do {\n}"); -- 2.7.4