]> granicus.if.org Git - clang/commitdiff
clang-format: Improve operator and template recognition.
authorDaniel Jasper <djasper@google.com>
Mon, 28 Jul 2014 13:19:58 +0000 (13:19 +0000)
committerDaniel Jasper <djasper@google.com>
Mon, 28 Jul 2014 13:19:58 +0000 (13:19 +0000)
Before:
  static_assert(is_convertible < A &&, B > ::value, "AAA");

After:
  static_assert(is_convertible<A &&, B>::value, "AAA");

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@214075 91177308-0d34-0410-b5e6-96231b3b80d8

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

index 6a7180bfb015d87d1725da6a383a3a87227ef4a1..885d147b9b60b277d1eece704355dc135ed1d33d 100644 (file)
@@ -69,12 +69,8 @@ private:
       // parameters.
       // FIXME: This is getting out of hand, write a decent parser.
       if (CurrentToken->Previous->isOneOf(tok::pipepipe, tok::ampamp) &&
-          ((CurrentToken->Previous->Type == TT_BinaryOperator &&
-            // Toplevel bool expressions do not make lots of sense;
-            // If we're on the top level, it contains only the base context and
-            // the context for the current opening angle bracket.
-            Contexts.size() > 2) ||
-           Contexts[Contexts.size() - 2].IsExpression) &&
+          CurrentToken->Previous->Type == TT_BinaryOperator &&
+          Contexts[Contexts.size() - 2].IsExpression &&
           Line.First->isNot(tok::kw_template))
         return false;
       updateParameterCount(Left, CurrentToken);
@@ -924,7 +920,7 @@ private:
 
     if (NextToken->is(tok::l_square) && NextToken->Type != TT_LambdaLSquare)
       return TT_PointerOrReference;
-    if (NextToken->is(tok::kw_operator))
+    if (NextToken->isOneOf(tok::kw_operator, tok::comma))
       return TT_PointerOrReference;
 
     if (PrevToken->is(tok::r_paren) && PrevToken->MatchingParen &&
index 28bdf3293aa805fa043f28cf4088005140b8fd3a..c942ae926dc954516eab516d9c4928a2a1a4b959 100644 (file)
@@ -4578,6 +4578,7 @@ TEST_F(FormatTest, UnderstandsTemplateParameters) {
   verifyFormat("aaaaaaaaaaaaaaaaaaaaaaaaaaaa(\n"
                "    aaaaaaaaaaaaaaaaaaaaaaaaaaaaa >> aaaaa);",
                getLLVMStyleWithColumns(60));
+  verifyFormat("static_assert(is_convertible<A &&, B>::value, \"AAA\");");
 }
 
 TEST_F(FormatTest, UnderstandsBinaryOperators) {
@@ -4883,7 +4884,7 @@ TEST_F(FormatTest, UnderstandsUsesOfStarAndAmp) {
 
   // FIXME: We cannot handle this case yet; we might be able to figure out that
   // foo<x> d > v; doesn't make sense.
-  verifyFormat("foo<a < b && c> d > v;");
+  verifyFormat("foo<a<b && c> d> v;");
 
   FormatStyle PointerMiddle = getLLVMStyle();
   PointerMiddle.PointerAlignment = FormatStyle::PAS_Middle;