From 3fc0bb779e751de71166c20a365cd5c28c3de8ed Mon Sep 17 00:00:00 2001 From: Daniel Jasper Date: Wed, 9 Jan 2013 10:40:23 +0000 Subject: [PATCH] Only align after assignments on the top level. This fixes llvm.org/PR14870 and we no longer mess up: template 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. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@171966 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Format/Format.cpp | 4 +++- unittests/Format/FormatTest.cpp | 8 ++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/Format/Format.cpp b/lib/Format/Format.cpp index 53dc97abec..1854d70d90 100644 --- a/lib/Format/Format.cpp +++ b/lib/Format/Format.cpp @@ -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; diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index 495fc7fee1..d4e5a51bc3 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -816,8 +816,9 @@ TEST_F(FormatTest, UnderstandsEquals) { "}"); verifyFormat( + // FIXME: Does an expression like this ever make sense? If yes, fix. "if (int aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa = 100000000 +\n" - " 10000000) {\n" + " 10000000) {\n" "}"); } @@ -872,7 +873,10 @@ TEST_F(FormatTest, WrapsTemplateDeclarations) { verifyFormat("template \n" "void aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(\n" " int aaaaaaaaaaaaaaaaa);"); - + verifyFormat( + "template \n" + "void f();"); } TEST_F(FormatTest, UnderstandsTemplateParameters) { -- 2.50.1