diff options
-rw-r--r-- | lib/Format/Format.cpp | 3 | ||||
-rw-r--r-- | unittests/Format/FormatTest.cpp | 5 |
2 files changed, 5 insertions, 3 deletions
diff --git a/lib/Format/Format.cpp b/lib/Format/Format.cpp index b1005b5de6..b4cbfec8c4 100644 --- a/lib/Format/Format.cpp +++ b/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/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index 2a3d66dfd7..0edb19166d 100644 --- a/unittests/Format/FormatTest.cpp +++ b/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}"); |