[clang] 05147d3 - [clang-format] Correctly parse function declarations with TypenameMacros
Alex Richardson via cfe-commits
cfe-commits at lists.llvm.org
Mon Sep 7 02:09:41 PDT 2020
Author: Alex Richardson
Date: 2020-09-07T10:09:18+01:00
New Revision: 05147d33091720e2df929d6fea3b0fd2a657ac61
URL: https://github.com/llvm/llvm-project/commit/05147d33091720e2df929d6fea3b0fd2a657ac61
DIFF: https://github.com/llvm/llvm-project/commit/05147d33091720e2df929d6fea3b0fd2a657ac61.diff
LOG: [clang-format] Correctly parse function declarations with TypenameMacros
When using the always break after return type setting:
Before:
SomeType funcdecl(LIST(uint64_t));
After:
SomeType
funcdecl(LIST(uint64_t));"
Reviewed By: MyDeveloperDay
Differential Revision: https://reviews.llvm.org/D87007
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 4867f9e3d6c1..5dd6a7a9da40 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -2400,6 +2400,8 @@ static bool isFunctionDeclarationName(const FormatToken &Current,
return true;
for (const FormatToken *Tok = Next->Next; Tok && Tok != Next->MatchingParen;
Tok = Tok->Next) {
+ if (Tok->is(TT_TypeDeclarationParen))
+ return true;
if (Tok->isOneOf(tok::l_paren, TT_TemplateOpener) && Tok->MatchingParen) {
Tok = Tok->MatchingParen;
continue;
diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp
index b1d46a27ef43..b198efa4af9e 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -6681,9 +6681,12 @@ TEST_F(FormatTest, ReturnTypeBreakingStyle) {
Style);
// All declarations and definitions should have the return type moved to its
- // own
- // line.
+ // own line.
Style.AlwaysBreakAfterReturnType = FormatStyle::RTBS_All;
+ Style.TypenameMacros = {"LIST"};
+ verifyFormat("SomeType\n"
+ "funcdecl(LIST(uint64_t));",
+ Style);
verifyFormat("class E {\n"
" int\n"
" f() {\n"
More information about the cfe-commits
mailing list