From b71508727859e1aef49c8f08e85cb3865a51a417 Mon Sep 17 00:00:00 2001 From: Daniel Jasper Date: Fri, 30 Aug 2013 10:10:19 +0000 Subject: clang-format: Improve recovery from enums with errors. Before: namespace n { enum Type { One, Two, // missing }; int i; } void g() { } After: namespace n { enum Type { One, Two, // missing }; int i; } void g() {} llvm-svn: 189662 --- clang/lib/Format/UnwrappedLineParser.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'clang/lib/Format/UnwrappedLineParser.cpp') diff --git a/clang/lib/Format/UnwrappedLineParser.cpp b/clang/lib/Format/UnwrappedLineParser.cpp index 9e4600b430d..fb63899f471 100644 --- a/clang/lib/Format/UnwrappedLineParser.cpp +++ b/clang/lib/Format/UnwrappedLineParser.cpp @@ -937,6 +937,7 @@ void UnwrappedLineParser::parseEnum() { if (FormatTok->Tok.is(tok::identifier)) nextToken(); } + bool HasError = false; if (FormatTok->Tok.is(tok::l_brace)) { if (Style.BreakBeforeBraces == FormatStyle::BS_Allman) addUnwrappedLine(); @@ -952,7 +953,17 @@ void UnwrappedLineParser::parseEnum() { addUnwrappedLine(); nextToken(); --Line->Level; + if (HasError) { + if (FormatTok->is(tok::semi)) + nextToken(); + addUnwrappedLine(); + } return; + case tok::semi: + HasError = true; + nextToken(); + addUnwrappedLine(); + break; case tok::comma: nextToken(); addUnwrappedLine(); -- cgit v1.2.3