From 6b3ff8c4caaa6782289a780e096fe56ad6434bb7 Mon Sep 17 00:00:00 2001 From: Daniel Jasper Date: Fri, 27 Sep 2013 08:29:16 +0000 Subject: [PATCH] clang-format: Improve formatting of functions with multiple trailing tokens. 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 | 5 ++++- unittests/Format/FormatTest.cpp | 4 ++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/Format/TokenAnnotator.cpp b/lib/Format/TokenAnnotator.cpp index e1e4f79d17..992104fe4c 100644 --- a/lib/Format/TokenAnnotator.cpp +++ b/lib/Format/TokenAnnotator.cpp @@ -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; diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index be2a45d199..d54c0421fc 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -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. -- 2.50.1