[llvm-branch-commits] [clang] ffd90ed - [clang-format] handle trailing comments in function definition detection
Tom Stellard via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Thu Sep 9 20:03:52 PDT 2021
Author: Krasimir Georgiev
Date: 2021-09-09T20:01:12-07:00
New Revision: ffd90ed19988658fcf1add9c7b9c19153e19cb74
URL: https://github.com/llvm/llvm-project/commit/ffd90ed19988658fcf1add9c7b9c19153e19cb74
DIFF: https://github.com/llvm/llvm-project/commit/ffd90ed19988658fcf1add9c7b9c19153e19cb74.diff
LOG: [clang-format] handle trailing comments in function definition detection
A follow-up to
https://github.com/llvm/llvm-project/commit/f6bc614546e169bb1b17a29c422ebace038e6c62
where we handle the case where the semicolon is followed by a trailing
comment.
Reviewed By: MyDeveloperDay
Differential Revision: https://reviews.llvm.org/D107907
(cherry picked from commit 0fc27ef19670676689d3317948c81eb171bb25f8)
Added:
Modified:
clang/lib/Format/TokenAnnotator.cpp
clang/unittests/Format/FormatTest.cpp
Removed:
################################################################################
diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp
index de3dabcfc639b..703eced09d446 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -2482,7 +2482,7 @@ static bool isFunctionDeclarationName(const FormatToken &Current,
// return i + 1;
// }
if (Next->Next && Next->Next->is(tok::identifier) &&
- Line.Last->isNot(tok::semi))
+ !Line.endsWith(tok::semi))
return true;
for (const FormatToken *Tok = Next->Next; Tok && Tok != Next->MatchingParen;
Tok = Tok->Next) {
diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp
index 67064d02c01a5..38b5aa45cc0ea 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -8244,6 +8244,9 @@ TEST_F(FormatTest, ReturnTypeBreakingStyle) {
verifyFormat("Tttttttttttttttttttttttt ppppppppppppppp\n"
" ABSL_GUARDED_BY(mutex) = {};",
getGoogleStyleWithColumns(40));
+ verifyFormat("Tttttttttttttttttttttttt ppppppppppppppp\n"
+ " ABSL_GUARDED_BY(mutex); // comment",
+ getGoogleStyleWithColumns(40));
Style = getGNUStyle();
More information about the llvm-branch-commits
mailing list