[PATCH] D104209: [clang-format] distinguish function type casts after 21c18d5a04316891110cecc2bf37ce51533decba
Krasimir Georgiev via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Jun 15 01:29:43 PDT 2021
This revision was automatically updated to reflect the committed changes.
Closed by commit rG54bd95cd96bc: [clang-format] distinguish function type casts after… (authored by krasimir).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D104209/new/
https://reviews.llvm.org/D104209
Files:
clang/lib/Format/TokenAnnotator.cpp
clang/unittests/Format/FormatTest.cpp
Index: clang/unittests/Format/FormatTest.cpp
===================================================================
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -8707,6 +8707,11 @@
verifyIndependentOfContext("MACRO('0' <= c && c <= '9');");
verifyFormat("void f() { f(float{1}, a * a); }");
verifyFormat("void f() { f(float(1), a * a); }");
+
+ verifyFormat("f((void (*)(int))g);");
+ verifyFormat("f((void (&)(int))g);");
+ verifyFormat("f((void (^)(int))g);");
+
// FIXME: Is there a way to make this work?
// verifyIndependentOfContext("MACRO(A *a);");
verifyFormat("MACRO(A &B);");
Index: clang/lib/Format/TokenAnnotator.cpp
===================================================================
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -397,9 +397,13 @@
!CurrentToken->Next->HasUnescapedNewline &&
!CurrentToken->Next->isTrailingComment())
HasMultipleParametersOnALine = true;
+ bool ProbablyFunctionTypeLParen =
+ (CurrentToken->is(tok::l_paren) && CurrentToken->Next &&
+ CurrentToken->Next->isOneOf(tok::star, tok::amp, tok::caret));
if ((CurrentToken->Previous->isOneOf(tok::kw_const, tok::kw_auto) ||
CurrentToken->Previous->isSimpleTypeSpecifier()) &&
- !CurrentToken->isOneOf(tok::l_brace, tok::l_paren))
+ !(CurrentToken->is(tok::l_brace) ||
+ (CurrentToken->is(tok::l_paren) && !ProbablyFunctionTypeLParen)))
Contexts.back().IsExpression = false;
if (CurrentToken->isOneOf(tok::semi, tok::colon)) {
MightBeObjCForRangeLoop = false;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D104209.352061.patch
Type: text/x-patch
Size: 1673 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210615/38defe39/attachment.bin>
More information about the cfe-commits
mailing list