Differential Revision: https://reviews.llvm.org/D60374

llvm-svn: 357877
This commit is contained in:
Owen Pan 2019-04-07 21:05:52 +00:00
parent f38b46ffca
commit e4f95e8e39
2 changed files with 27 additions and 3 deletions

View File

@ -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;

View File

@ -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;