]> granicus.if.org Git - clang/commitdiff
clang-format: Don't force a break after "endl" if everything fits on one line.
authorDaniel Jasper <djasper@google.com>
Tue, 17 Feb 2015 10:05:15 +0000 (10:05 +0000)
committerDaniel Jasper <djasper@google.com>
Tue, 17 Feb 2015 10:05:15 +0000 (10:05 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@229486 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Format/ContinuationIndenter.cpp
lib/Format/TokenAnnotator.cpp
unittests/Format/FormatTest.cpp

index a02cb68072899c92865c138b6fdd24f036c40023..7b36cac5dc1ed4d2dbf960106d9420e2ec741a06 100644 (file)
@@ -232,6 +232,10 @@ bool ContinuationIndenter::mustBreak(const LineState &State) {
       Previous.is(tok::l_brace) && !Current.isOneOf(tok::r_brace, tok::comment))
     return true;
 
+  if (Current.is(tok::lessless) && Previous.is(tok::identifier) &&
+      Previous.TokenText == "endl")
+    return true;
+
   return false;
 }
 
index e00db2127d6d57c4fbad0653051e998954647421..dc48d8655101db7d3b207febeaae0d700535e7b5 100644 (file)
@@ -1903,9 +1903,6 @@ bool TokenAnnotator::mustBreakBefore(const AnnotatedLine &Line,
     return true;
   if (Left.is(TT_ObjCBlockLBrace) && !Style.AllowShortBlocksOnASingleLine)
     return true;
-  if (Right.is(tok::lessless) && Left.is(tok::identifier) &&
-      Left.TokenText == "endl")
-    return true;
 
   if (Style.Language == FormatStyle::LK_JavaScript) {
     // FIXME: This might apply to other languages and token kinds.
index 52761f163ac3ab71a7f0746b35350cbeaad8d9b0..9f7becb3c0c31815f4f42e63ff04ec8130969564 100644 (file)
@@ -4762,8 +4762,9 @@ TEST_F(FormatTest, AlignsPipes) {
                "}");
 
   // Handle 'endl'.
-  verifyFormat("llvm::errs() << aaaa << endl\n"
-               "             << bbbb << endl;");
+  verifyFormat("llvm::errs() << aaaaaaaaaaaaaaaaaaaaaa << endl\n"
+               "             << bbbbbbbbbbbbbbbbbbbbbb << endl;");
+  verifyFormat("llvm::errs() << endl << bbbbbbbbbbbbbbbbbbbbbb << endl;");
 }
 
 TEST_F(FormatTest, UnderstandsEquals) {