clang-format: Last line in incomplete block is indented incorrectly
authorMarianne Mailhot-Sarrasin <marianne.mailhot.sarrasin@gmail.com>
Thu, 14 Apr 2016 14:56:49 +0000 (14:56 +0000)
committerMarianne Mailhot-Sarrasin <marianne.mailhot.sarrasin@gmail.com>
Thu, 14 Apr 2016 14:56:49 +0000 (14:56 +0000)
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

llvm-svn: 266321

clang/lib/Format/UnwrappedLineParser.cpp
clang/unittests/Format/FormatTest.cpp

index 76e8776..6cd74f9 100644 (file)
@@ -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;
index 50a83f6..1b0e586 100644 (file)
@@ -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) {