]> granicus.if.org Git - clang/commitdiff
clang-format: Improve formatting of functions with multiple trailing tokens.
authorDaniel Jasper <djasper@google.com>
Fri, 27 Sep 2013 08:29:16 +0000 (08:29 +0000)
committerDaniel Jasper <djasper@google.com>
Fri, 27 Sep 2013 08:29:16 +0000 (08:29 +0000)
Before:
  void SomeFunction(aaaaaaaaaaaaaaaaaaaaaaaaaa,
                    aaaaaaaaaaaaaaaaaaaaaaaaaa) override
  final;

After:
  void SomeFunction(aaaaaaaaaaaaaaaaaaaaaaaaaa,
                    aaaaaaaaaaaaaaaaaaaaaaaaaa) override final;

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

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

index e1e4f79d1773574bbf4abbe4e4be96038bf66c3a..992104fe4c235431acf20819174f26cf986131fd 100644 (file)
@@ -606,7 +606,10 @@ private:
     }
 
     if (Current.Type == TT_Unknown) {
-      if (isStartOfName(Current)) {
+      // Line.MightBeFunctionDecl can only be true after the parentheses of a
+      // function declaration have been found. In this case, 'Current' is a
+      // trailing token of this declaration and thus cannot be a name.
+      if (isStartOfName(Current) && !Line.MightBeFunctionDecl) {
         Contexts.back().FirstStartOfName = &Current;
         Current.Type = TT_StartOfName;
         NameFound = true;
index be2a45d1996b92a4b41a493ee216c14eb0d5db72..d54c0421fc3e4716c0cc0acabce7d56566d66116 100644 (file)
@@ -2776,6 +2776,10 @@ TEST_F(FormatTest, BreaksFunctionDeclarationsWithTrailingTokens) {
   // function-like.
   verifyFormat("void SomeFunction(aaaaaaaaaaaaaaaaaaaaaaaaaa,\n"
                "                  aaaaaaaaaaaaaaaaaaaaaaaaaa) OVERRIDE;");
+  verifyFormat("void SomeFunction(aaaaaaaaaaaaaaaaaaaaaaaaaa,\n"
+               "                  aaaaaaaaaaaaaaaaaaaaaaaaaa) OVERRIDE FINAL;");
+  verifyFormat("void SomeFunction(aaaaaaaaaaaaaaaaaaaaaaaaaa,\n"
+               "                  aaaaaaaaaaaaaaaaaaaaaaaaaa) override final;");
 
   // Breaking before function-like trailing annotations is fine to keep them
   // close to their arguments.