From: Marianne Mailhot-Sarrasin Date: Thu, 14 Apr 2016 14:56:49 +0000 (+0000) Subject: clang-format: Last line in incomplete block is indented incorrectly X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=463ccc6b430b33c924e1d942390c78ee48b2381f;p=clang clang-format: Last line in incomplete block is indented incorrectly Indentation of the last line was reset to the initial indentation of the block when reaching EOF. Patch by Maxime Beaulieu Differential Revision: http://reviews.llvm.org/D19065 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@266321 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Format/UnwrappedLineParser.cpp b/lib/Format/UnwrappedLineParser.cpp index 76e87768bc..6cd74f91a8 100644 --- a/lib/Format/UnwrappedLineParser.cpp +++ b/lib/Format/UnwrappedLineParser.cpp @@ -430,6 +430,9 @@ void UnwrappedLineParser::parseBlock(bool MustBeDeclaration, bool AddLevel, ++Line->Level; parseLevel(/*HasOpeningBrace=*/true); + if (eof()) + return; + if (MacroBlock ? !FormatTok->is(TT_MacroBlockEnd) : !FormatTok->is(tok::r_brace)) { Line->Level = InitialLevel; diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index 50a83f66ad..1b0e5865b7 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -7110,10 +7110,9 @@ TEST_F(FormatTest, BlockCommentsAtEndOfLine) { } TEST_F(FormatTest, IndentLineCommentsInStartOfBlockAtEndOfFile) { - // FIXME: This is not what we want... verifyFormat("{\n" - "// a" - "// b"); + " // a\n" + " // b"); } TEST_F(FormatTest, FormatStarDependingOnContext) {