From 7b27a10b1e95804e1272d44f499f81648fb991b8 Mon Sep 17 00:00:00 2001 From: Daniel Jasper Date: Mon, 27 May 2013 12:45:09 +0000 Subject: [PATCH] Improve indentation of assignments. Before: unsigned OriginalStartColumn = SourceMgr.getSpellingColumnNumber( Current.FormatTok.getStartOfNonWhitespace()) - 1; After: unsigned OriginalStartColumn = SourceMgr.getSpellingColumnNumber( Current.FormatTok.getStartOfNonWhitespace()) - 1; llvm-svn: 182733 --- clang/lib/Format/Format.cpp | 5 ++++- clang/unittests/Format/FormatTest.cpp | 4 ++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp index dcb5f8a6edae..b4ea90462a83 100644 --- a/clang/lib/Format/Format.cpp +++ b/clang/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/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index 132dbb5aa214..73fea60519fe 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/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) {