r357877 - [clang-format] Fix bug https://bugs.llvm.org/show_bug.cgi?id=41413
Owen Pan via cfe-commits
cfe-commits at lists.llvm.org
Sun Apr 7 14:05:52 PDT 2019
Author: owenpan
Date: Sun Apr 7 14:05:52 2019
New Revision: 357877
URL: http://llvm.org/viewvc/llvm-project?rev=357877&view=rev
Log:
[clang-format] Fix bug https://bugs.llvm.org/show_bug.cgi?id=41413
Differential Revision: https://reviews.llvm.org/D60374
Modified:
cfe/trunk/lib/Format/ContinuationIndenter.cpp
cfe/trunk/unittests/Format/FormatTest.cpp
Modified: cfe/trunk/lib/Format/ContinuationIndenter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/ContinuationIndenter.cpp?rev=357877&r1=357876&r2=357877&view=diff
==============================================================================
--- cfe/trunk/lib/Format/ContinuationIndenter.cpp (original)
+++ cfe/trunk/lib/Format/ContinuationIndenter.cpp Sun Apr 7 14:05:52 2019
@@ -945,18 +945,24 @@ unsigned ContinuationIndenter::getNewLin
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;
Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=357877&r1=357876&r2=357877&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Sun Apr 7 14:05:52 2019
@@ -12822,6 +12822,24 @@ TEST_F(FormatTest, ConfigurableContinuat
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;
More information about the cfe-commits
mailing list