From: Owen Pan Date: Sun, 7 Apr 2019 21:05:52 +0000 (+0000) Subject: [clang-format] Fix bug https://bugs.llvm.org/show_bug.cgi?id=41413 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=7e0382b1715d2b3b4f58fbb87f64e3c5753bc052;p=clang [clang-format] Fix bug https://bugs.llvm.org/show_bug.cgi?id=41413 Differential Revision: https://reviews.llvm.org/D60374 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@357877 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Format/ContinuationIndenter.cpp b/lib/Format/ContinuationIndenter.cpp index 577d96d52c..6be7f7e1b5 100644 --- a/lib/Format/ContinuationIndenter.cpp +++ b/lib/Format/ContinuationIndenter.cpp @@ -945,18 +945,24 @@ unsigned ContinuationIndenter::getNewLineColumn(const LineState &State) { return State.Stack[State.Stack.size() - 2].LastSpace; return State.FirstIndent; } - // Indent a closing parenthesis at the previous level if followed by a semi or - // opening brace. This allows indentations such as: + // Indent a closing parenthesis at the previous level if followed by a semi, + // const, or opening brace. This allows indentations such as: // foo( // a, // ); + // int Foo::getter( + // // + // ) const { + // return foo; + // } // function foo( // a, // ) { // code(); // // } if (Current.is(tok::r_paren) && State.Stack.size() > 1 && - (!Current.Next || Current.Next->isOneOf(tok::semi, tok::l_brace))) + (!Current.Next || + Current.Next->isOneOf(tok::semi, tok::kw_const, tok::l_brace))) return State.Stack[State.Stack.size() - 2].LastSpace; if (NextNonComment->is(TT_TemplateString) && NextNonComment->closesScope()) return State.Stack[State.Stack.size() - 2].LastSpace; diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index dc2512a9e2..3256ea54ab 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -12822,6 +12822,24 @@ TEST_F(FormatTest, ConfigurableContinuationIndentWidth) { format("int i = longFunction(arg);", SixIndent)); } +TEST_F(FormatTest, WrappedClosingParenthesisIndent) { + FormatStyle Style = getLLVMStyle(); + verifyFormat( + "int Foo::getter(\n" + " //\n" + ") const {\n" + " return foo;\n" + "}", + Style); + verifyFormat( + "void Foo::setter(\n" + " //\n" + ") {\n" + " foo = 1;\n" + "}", + Style); +} + TEST_F(FormatTest, SpacesInAngles) { FormatStyle Spaces = getLLVMStyle(); Spaces.SpacesInAngles = true;