r186120 - clang-format: Fix bug concerning the alignment of "}".

Daniel Jasper djasper at google.com
Thu Jul 11 14:27:40 PDT 2013


Author: djasper
Date: Thu Jul 11 16:27:40 2013
New Revision: 186120

URL: http://llvm.org/viewvc/llvm-project?rev=186120&view=rev
Log:
clang-format: Fix bug concerning the alignment of "}".

Before:
    int i;  // indented 2 space more than clang-format would use.
    SomeReturnType  // clang-format invoked on this line.
    SomeFunctionMakingLBraceEndInColumn80() {
  }  // This is the indent clang-format would prefer.

After:
    int i;  // indented 2 space more than clang-format would use.
    SomeReturnType  // clang-format invoked on this line.
    SomeFunctionMakingLBraceEndInColumn80() {
    }

Modified:
    cfe/trunk/lib/Format/Format.cpp
    cfe/trunk/unittests/Format/FormatTest.cpp

Modified: cfe/trunk/lib/Format/Format.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/Format.cpp?rev=186120&r1=186119&r2=186120&view=diff
==============================================================================
--- cfe/trunk/lib/Format/Format.cpp (original)
+++ cfe/trunk/lib/Format/Format.cpp Thu Jul 11 16:27:40 2013
@@ -536,7 +536,7 @@ private:
         if (Current.BlockKind == BK_BracedInit)
           State.Column = State.Stack[State.Stack.size() - 2].LastSpace;
         else
-          State.Column = Line.Level * Style.IndentWidth;
+          State.Column = FirstIndent;
       } else if (Current.is(tok::string_literal) &&
                  State.StartOfStringLiteral != 0) {
         State.Column = State.StartOfStringLiteral;

Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=186120&r1=186119&r2=186120&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Thu Jul 11 16:27:40 2013
@@ -4810,6 +4810,13 @@ TEST_F(FormatTest, ReformatRegionAdjusts
                    "       // line 2\n"
                    "  int b;",
                    35, 0, getLLVMStyle()));
+  EXPECT_EQ("  int a;\n"
+            "  void\n"
+            "  ffffff() {\n"
+            "  }",
+            format("  int a;\n"
+                   "void ffffff() {}",
+                   11, 0, getLLVMStyleWithColumns(11)));
 }
 
 TEST_F(FormatTest, BreakStringLiterals) {





More information about the cfe-commits mailing list