]> granicus.if.org Git - clang/commitdiff
clang-format: Understand functions with decltype return type.
authorDaniel Jasper <djasper@google.com>
Mon, 5 May 2014 13:48:09 +0000 (13:48 +0000)
committerDaniel Jasper <djasper@google.com>
Mon, 5 May 2014 13:48:09 +0000 (13:48 +0000)
Before:
  decltype(long_name_forcing_break)
      f() {}

After:
  decltype(long_name_forcing_break)
  f() {}

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

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

index a6e04c54a21942c4368eebdbe2b974cc710e59da..e2e342c459345b98d23da43577ce6196f37699ec 100644 (file)
@@ -414,7 +414,9 @@ private:
       if (!parseParens())
         return false;
       if (Line.MustBeDeclaration && Contexts.size() == 1 &&
-          !Contexts.back().IsExpression && Line.First->Type != TT_ObjCProperty)
+          !Contexts.back().IsExpression &&
+          Line.First->Type != TT_ObjCProperty &&
+          (!Tok->Previous || Tok->Previous->isNot(tok::kw_decltype)))
         Line.MightBeFunctionDecl = true;
       break;
     case tok::l_square:
@@ -869,6 +871,11 @@ private:
              PreviousNotConst->MatchingParen->Previous &&
              PreviousNotConst->MatchingParen->Previous->isNot(tok::kw_template);
 
+    if (PreviousNotConst->is(tok::r_paren) && PreviousNotConst->MatchingParen &&
+        PreviousNotConst->MatchingParen->Previous &&
+        PreviousNotConst->MatchingParen->Previous->is(tok::kw_decltype))
+      return true;
+
     return (!IsPPKeyword && PreviousNotConst->is(tok::identifier)) ||
            PreviousNotConst->Type == TT_PointerOrReference ||
            PreviousNotConst->isSimpleTypeSpecifier();
index d1f4c86bda861aba9dae0994f639c8424a4426c7..e80d1e3d112db2c28fd2ef0ce4372578721128a5 100644 (file)
@@ -4840,6 +4840,8 @@ TEST_F(FormatTest, BreaksLongDeclarations) {
                "LooooooooooooooooooooooooooooooooooongFunctionDefinition() {}");
   verifyFormat("LoooooooooooooooooooooooooooooooooooooooongReturnType const\n"
                "LooooooooooooooooooooooooooooooooooongFunctionDefinition() {}");
+  verifyFormat("decltype(LoooooooooooooooooooooooooooooooooooooooongName)\n"
+               "LooooooooooooooooooooooooooooooooooongFunctionDefinition() {}");
 
   // FIXME: Without the comment, this breaks after "(".
   verifyFormat("LoooooooooooooooooooooooooooooooooooooooongType  // break\n"