Automatically munch semicolons after blocks.
While it is mostly a user error to have the extra semicolon,
formatting it graciously will correctly format in the cases
where we do not fully understand the code (macros).
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@192543 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Format/UnwrappedLineParser.cpp b/lib/Format/UnwrappedLineParser.cpp
index e8503bb..949f5a3 100644
--- a/lib/Format/UnwrappedLineParser.cpp
+++ b/lib/Format/UnwrappedLineParser.cpp
@@ -360,7 +360,8 @@
FormatTok = Tokens->setPosition(StoredPosition);
}
-void UnwrappedLineParser::parseBlock(bool MustBeDeclaration, bool AddLevel) {
+void UnwrappedLineParser::parseBlock(bool MustBeDeclaration, bool AddLevel,
+ bool MunchSemi) {
assert(FormatTok->Tok.is(tok::l_brace) && "'{' expected");
unsigned InitialLevel = Line->Level;
nextToken();
@@ -380,6 +381,8 @@
}
nextToken(); // Munch the closing brace.
+ if (MunchSemi && FormatTok->Tok.is(tok::semi))
+ nextToken();
Line->Level = InitialLevel;
}
@@ -1160,7 +1163,8 @@
Style.BreakBeforeBraces == FormatStyle::BS_Allman)
addUnwrappedLine();
- parseBlock(/*MustBeDeclaration=*/true);
+ parseBlock(/*MustBeDeclaration=*/true, /*Addlevel=*/true,
+ /*MunchSemi=*/false);
}
// We fall through to parsing a structural element afterwards, so
// class A {} n, m;