From c7345ccc2c4732603d2803d10b2b235807727057 Mon Sep 17 00:00:00 2001 From: Daniel Jasper Date: Mon, 7 Jan 2013 07:13:20 +0000 Subject: [PATCH] Put a higher penalty on breaking before "." or "->". This fixes llvm.org/PR14823. Before: local_state->SetString(prefs::kApplicationLocale, parent_local_state ->GetString(prefs::kApplicationLocale)); After: local_state->SetString( prefs::kApplicationLocale, parent_local_state->GetString(prefs::kApplicationLocale)); llvm-svn: 171705 --- clang/lib/Format/Format.cpp | 4 ++-- clang/unittests/Format/FormatTest.cpp | 5 +++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp index 4d401a5be9e1..c6ff8801861d 100644 --- a/clang/lib/Format/Format.cpp +++ b/clang/lib/Format/Format.cpp @@ -99,7 +99,7 @@ public: Annotations(Annotations), Replaces(Replaces), StructuralError(StructuralError) { Parameters.PenaltyIndentLevel = 15; - Parameters.PenaltyLevelDecrease = 10; + Parameters.PenaltyLevelDecrease = 30; } /// \brief Formats an \c UnwrappedLine. @@ -369,7 +369,7 @@ private: return Level; if (Right.Tok.is(tok::arrow) || Right.Tok.is(tok::period)) - return 50; + return 150; return 3; } diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index 28f63aa05512..de794dabb6cc 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -713,9 +713,14 @@ TEST_F(FormatTest, WrapsAtFunctionCallsIfNecessary) { "function(LoooooooooooooooooooooooooooooooooooongObject\n" " ->loooooooooooooooooooooooooooooooooooooooongFunction());"); + // Here, it is not necessary to wrap at "." or "->". verifyFormat("if (aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(aaaaaaaaaaaa) ||\n" " aaaa.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) {\n" "}"); + verifyFormat( + "aaaaaaaaaaa->aaaaaaaaa(\n" + " aaaaaaaaaaaaaaaaaaaaaaaaa,\n" + " aaaaaaaaaaaaaaaaaa->aaaaaaaaa(aaaaaaaaaaaaaaaaaaaaaaaaa));\n"); } TEST_F(FormatTest, WrapsTemplateDeclarations) {