From a0740f5ddf143d59b8e55d2cb6e39ed5059575b4 Mon Sep 17 00:00:00 2001 From: Daniel Jasper Date: Fri, 12 Jul 2013 15:14:05 +0000 Subject: [PATCH] clang-format: Improve <<-formatting. This fixes a regression caused by r186115. Before: Diag(aaaaaaaaaaaaaaaaaaaaaaaaaaaaa, bbbbbbbbb) << aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa << aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa; After: Diag(aaaaaaaaaaaaaaaaaaaaaaaaaaaaa, bbbbbbbbb) << aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa << aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa; git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@186164 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Format/Format.cpp | 5 +++++ unittests/Format/FormatTest.cpp | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/lib/Format/Format.cpp b/lib/Format/Format.cpp index 224f1d759f..e1a0874e06 100644 --- a/lib/Format/Format.cpp +++ b/lib/Format/Format.cpp @@ -1174,6 +1174,11 @@ private: State.Stack.back().BreakBeforeParameter) return true; + // Same as above, but for the first "<<" operator. + if (Current.is(tok::lessless) && State.Stack.back().BreakBeforeParameter && + State.Stack.back().FirstLessLess == 0) + return true; + // FIXME: Comparing LongestObjCSelectorName to 0 is a hacky way of finding // out whether it is the first parameter. Clean this up. if (Current.Type == TT_ObjCSelectorName && diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index 4ca5bb49b6..241609051a 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -3026,6 +3026,11 @@ TEST_F(FormatTest, AlignsPipes) { " << aaaaaaaaaaaaaaaaaaaaaaaaaaaa;", getLLVMStyleWithColumns(70)); + // But sometimes, breaking before the first "<<" is necessary. + verifyFormat("Diag(aaaaaaaaaaaaaaaaaaaaaaaaaaaaa, bbbbbbbbb)\n" + " << aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n" + " << aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa;"); + verifyFormat( "llvm::errs() << aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n" " .aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa();"); -- 2.40.0