r232717 - clang-format: Fix another bug in wrapping around "*".

Daniel Jasper djasper at google.com
Thu Mar 19 02:40:16 PDT 2015


Author: djasper
Date: Thu Mar 19 04:40:16 2015
New Revision: 232717

URL: http://llvm.org/viewvc/llvm-project?rev=232717&view=rev
Log:
clang-format: Fix another bug in wrapping around "*".

Before:
  void aaaaa(
      aaaaaaaaaaaa* aaaaaaaaaaaaaa) {} // even violation the column limit

After:
  void aaaaa(aaaaaaaaaaaa*
                 aaaaaaaaaaaaaa) {}

Modified:
    cfe/trunk/lib/Format/TokenAnnotator.cpp
    cfe/trunk/unittests/Format/FormatTest.cpp

Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=232717&r1=232716&r2=232717&view=diff
==============================================================================
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Thu Mar 19 04:40:16 2015
@@ -1538,7 +1538,7 @@ unsigned TokenAnnotator::splitPenalty(co
     return 200;
   }
   if (Right.is(TT_PointerOrReference))
-    return 200;
+    return 190;
   if (Right.is(TT_TrailingReturnArrow))
     return 110;
   if (Left.is(tok::equal) && Right.is(tok::l_brace))
@@ -1995,8 +1995,6 @@ bool TokenAnnotator::canBreakBefore(cons
     return false;
   if (Left.isOneOf(TT_JavaAnnotation, TT_LeadingJavaAnnotation))
     return !Right.is(tok::l_paren);
-  if (Left.is(TT_PointerOrReference))
-    return Right.is(TT_FunctionDeclarationName);
   if (Right.is(TT_PointerOrReference))
     return Line.IsMultiVariableDeclStmt ||
            (Style.PointerAlignment == FormatStyle::PAS_Right &&
@@ -2004,6 +2002,8 @@ bool TokenAnnotator::canBreakBefore(cons
   if (Right.isOneOf(TT_StartOfName, TT_FunctionDeclarationName) ||
       Right.is(tok::kw_operator))
     return true;
+  if (Left.is(TT_PointerOrReference))
+    return false;
   if (Right.isTrailingComment())
     // We rely on MustBreakBefore being set correctly here as we should not
     // change the "binding" behavior of a comment.

Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=232717&r1=232716&r2=232717&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Thu Mar 19 04:40:16 2015
@@ -3780,6 +3780,10 @@ TEST_F(FormatTest, BreaksFunctionDeclara
   verifyFormat("void aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(\n"
                "    aaaaaaaaaaaaaaaaaaaaaaaaa* const aaaaaaaaaaaa) {}",
                Style);
+  verifyFormat(
+      "void aaaaaaa(aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa*\n"
+      "                 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) {}",
+      Style);
 }
 
 TEST_F(FormatTest, TrailingReturnType) {





More information about the cfe-commits mailing list