From 06451fa1a22d3b285c56668f80ec52207a4aa6fd Mon Sep 17 00:00:00 2001 From: Krasimir Georgiev Date: Fri, 21 Jul 2017 10:26:13 +0000 Subject: [clang-format] Fix comment levels between '}' and PPDirective Summary: This fixes a regression exposed by r307795 in which the level of a comment line between '}' and a preprocessor directive is incorrectly set as the level of the line before the '}'. In effect, this: ``` int f(int i) { int j = i; return i + j; } // comment #ifdef A #endif ``` was formatted as: ``` int f(int i) { int j = i; return i + j; } // comment #ifdef A #endif ``` Reviewers: djasper Reviewed By: djasper Subscribers: cfe-commits, klimek Differential Revision: https://reviews.llvm.org/D35485 llvm-svn: 308725 --- clang/lib/Format/UnwrappedLineParser.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'clang/lib') diff --git a/clang/lib/Format/UnwrappedLineParser.cpp b/clang/lib/Format/UnwrappedLineParser.cpp index faac5a371c2..4858e596ca4 100644 --- a/clang/lib/Format/UnwrappedLineParser.cpp +++ b/clang/lib/Format/UnwrappedLineParser.cpp @@ -486,6 +486,8 @@ void UnwrappedLineParser::parseBlock(bool MustBeDeclaration, bool AddLevel, return; } + flushComments(isOnNewLine(*FormatTok)); + Line->Level = InitialLevel; nextToken(); // Munch the closing brace. if (MacroBlock && FormatTok->is(tok::l_paren)) @@ -493,7 +495,6 @@ void UnwrappedLineParser::parseBlock(bool MustBeDeclaration, bool AddLevel, if (MunchSemi && FormatTok->Tok.is(tok::semi)) nextToken(); - Line->Level = InitialLevel; Line->MatchingOpeningBlockLineIndex = OpeningLineIndex; if (OpeningLineIndex != UnwrappedLine::kInvalidIndex) { // Update the opening line to add the forward reference as well -- cgit v1.2.3