]> granicus.if.org Git - clang/commitdiff
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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@266321 91177308-0d34-0410-b5e6-96231b3b80d8

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

index 76e87768bc6b96b99d54733c80a581186d40e10b..6cd74f91a8aac16f1db9c7cd2ba7e381bc534ef5 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 50a83f66ad2a0e3294cf767d584b75a39a35e90d..1b0e5865b771a471deb7c4ab542942ea76c62319 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) {