]> granicus.if.org Git - clang/commitdiff
clang-format: Always allow break after leading annotations.
authorDaniel Jasper <djasper@google.com>
Mon, 24 Aug 2015 15:10:01 +0000 (15:10 +0000)
committerDaniel Jasper <djasper@google.com>
Mon, 24 Aug 2015 15:10:01 +0000 (15:10 +0000)
Before:
  DEPRECATED("Use NewClass::NewFunction instead.") int OldFunction(
  const string &parameter) {}

Could not be formatted at all, as clang-format would both require and
disallow the break before "int".

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

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

index 50e04310b636851ce18b97827144e61c57d8aa68..ac34df2455f06f270d23389b465d74caef9ff958 100644 (file)
@@ -2236,7 +2236,7 @@ bool TokenAnnotator::canBreakBefore(const AnnotatedLine &Line,
     return Left.isNot(tok::period); // FIXME: Properly parse ObjC calls.
   if (Left.is(tok::r_paren) && Line.Type == LT_ObjCProperty)
     return true;
-  if (Left.ClosesTemplateDeclaration)
+  if (Left.ClosesTemplateDeclaration || Left.is(TT_FunctionAnnotationRParen))
     return true;
   if (Right.isOneOf(TT_RangeBasedForLoopColon, TT_OverloadedOperatorLParen,
                     TT_OverloadedOperator))
index 3751697392916753e3b71f1637143614ca35b822..2bcc678cbb488480a7e7ff23deb54e829cce55aa 100644 (file)
@@ -3899,6 +3899,8 @@ TEST_F(FormatTest, BreaksFunctionDeclarationsWithTrailingTokens) {
 }
 
 TEST_F(FormatTest, FunctionAnnotations) {
+  verifyFormat("DEPRECATED(\"Use NewClass::NewFunction instead.\")\n"
+               "int OldFunction(const string &parameter) {}");
   verifyFormat("DEPRECATED(\"Use NewClass::NewFunction instead.\")\n"
                "string OldFunction(const string &parameter) {}");
   verifyFormat("template <typename T>\n"