From: Daniel Jasper Date: Mon, 27 May 2013 12:45:09 +0000 (+0000) Subject: Improve indentation of assignments. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=512843a7dc01a4f1755e699d1e394a691a39c176;p=clang Improve indentation of assignments. Before: unsigned OriginalStartColumn = SourceMgr.getSpellingColumnNumber( Current.FormatTok.getStartOfNonWhitespace()) - 1; After: unsigned OriginalStartColumn = SourceMgr.getSpellingColumnNumber( Current.FormatTok.getStartOfNonWhitespace()) - 1; git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@182733 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Format/Format.cpp b/lib/Format/Format.cpp index dcb5f8a6ed..b4ea90462a 100644 --- a/lib/Format/Format.cpp +++ b/lib/Format/Format.cpp @@ -640,7 +640,10 @@ private: else if ((Previous.Type == TT_BinaryOperator || Previous.Type == TT_ConditionalExpr || Previous.Type == TT_CtorInitializerColon) && - getPrecedence(Previous) != prec::Assignment) + !(getPrecedence(Previous) == prec::Assignment && + Current.FakeLParens.empty())) + // Always indent relative to the RHS of the expression unless this is a + // simple assignment without binary expression on the RHS. State.Stack.back().LastSpace = State.Column; else if (Previous.Type == TT_InheritanceColon) State.Stack.back().Indent = State.Column; diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index 132dbb5aa2..73fea60519 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -2336,6 +2336,10 @@ TEST_F(FormatTest, BreaksAfterAssignments) { verifyFormat( "aaaaaaaaaaaaaaaaaaaaaaaaaa aaaa = aaaaaaaaaaaaaa(0).aaaa()\n" " .aaaaaaaaaaaa(aaaaaaaaaaaaaaaaaaa::aaaaaaaaaaaaaaaaaaaaa);"); + verifyFormat("unsigned OriginalStartColumn =\n" + " SourceMgr.getSpellingColumnNumber(\n" + " Current.FormatTok.getStartOfNonWhitespace()) -\n" + " 1;"); } TEST_F(FormatTest, AlignsAfterAssignments) {