Author: Krasimir Georgiev Date: 2021-06-15T10:28:36+02:00 New Revision: 54bd95cd96bc7305219b594f95d7d1f447ee4c94
URL: https://github.com/llvm/llvm-project/commit/54bd95cd96bc7305219b594f95d7d1f447ee4c94 DIFF: https://github.com/llvm/llvm-project/commit/54bd95cd96bc7305219b594f95d7d1f447ee4c94.diff LOG: [clang-format] distinguish function type casts after 21c18d5a04316891110cecc2bf37ce51533decba https://github.com/llvm/llvm-project/commit/21c18d5a04316891110cecc2bf37ce51533decba improved the detection of multiplication in function call argument lists, but unintentionally regressed the handling of function type casts (there were no tests covering those). This patch improves the detection of function type casts and adds a few tests. Reviewed By: HazardyKnusperkeks Differential Revision: https://reviews.llvm.org/D104209 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 750839c57c162..a3d8637452978 100755 --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/lib/Format/TokenAnnotator.cpp @@ -397,9 +397,13 @@ class AnnotatingParser { !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; diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index 279f2b3119fc9..3df5d23a930f1 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -8707,6 +8707,11 @@ TEST_F(FormatTest, UnderstandsUsesOfStarAndAmp) { 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);"); _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits