From: Daniel Jasper Date: Thu, 11 Jul 2013 21:27:40 +0000 (+0000) Subject: clang-format: Fix bug concerning the alignment of "}". X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=15ec3a871d5ae8a8d4c29ca2681532a9894898b6;p=clang 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() { } git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@186120 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Format/Format.cpp b/lib/Format/Format.cpp index 680bb13013..a98d565caa 100644 --- a/lib/Format/Format.cpp +++ b/lib/Format/Format.cpp @@ -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; diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index ae4d9f5c0d..6e53f92e5a 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -4810,6 +4810,13 @@ TEST_F(FormatTest, ReformatRegionAdjustsIndent) { " // 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) {