Only align after assignments on the top level.

This fixes llvm.org/PR14870 and we no longer mess up:
template <typename T1, typename T2 = char, typename T3 = char,
          typename T4 = char>
void f();

It removes the nice aligment for assignments inside other expressions,
but I am not sure those are actually practically relevant. If so, we can
fix those later.

llvm-svn: 171966
This commit is contained in:
Daniel Jasper 2013-01-09 10:40:23 +00:00
parent 652b9ab7df
commit bcab430fee
2 changed files with 9 additions and 3 deletions

View File

@ -333,7 +333,9 @@ private:
if (!DryRun)
replaceWhitespace(Current, 0, Spaces);
if (RootToken.isNot(tok::kw_for) &&
// FIXME: Do we need to do this for assignments nested in other
// expressions?
if (RootToken.isNot(tok::kw_for) && ParenLevel == 0 &&
(getPrecedence(Previous) == prec::Assignment ||
Previous.is(tok::kw_return)))
State.Indent[ParenLevel] = State.Column + Spaces;

View File

@ -816,6 +816,7 @@ TEST_F(FormatTest, UnderstandsEquals) {
"}");
verifyFormat(
// FIXME: Does an expression like this ever make sense? If yes, fix.
"if (int aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa = 100000000 +\n"
" 10000000) {\n"
"}");
@ -872,7 +873,10 @@ TEST_F(FormatTest, WrapsTemplateDeclarations) {
verifyFormat("template <typename T>\n"
"void aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(\n"
" int aaaaaaaaaaaaaaaaa);");
verifyFormat(
"template <typename T1, typename T2 = char, typename T3 = char,\n"
" typename T4 = char>\n"
"void f();");
}
TEST_F(FormatTest, UnderstandsTemplateParameters) {