From db8afe424991b34884afb13ecf97ac458e41da9e Mon Sep 17 00:00:00 2001 From: Daniel Jasper Date: Tue, 10 Sep 2013 10:26:38 +0000 Subject: [PATCH] clang-format: Understand function type typedefs with typeof. Before: typedef typeof(int(int, int)) * MyFunc; After: typedef typeof(int(int, int)) *MyFunc; This fixes llvm.org/PR17178. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@190401 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Format/TokenAnnotator.cpp | 5 +++++ unittests/Format/FormatTest.cpp | 1 + 2 files changed, 6 insertions(+) diff --git a/lib/Format/TokenAnnotator.cpp b/lib/Format/TokenAnnotator.cpp index c0897ca68c..d9aef602d3 100644 --- a/lib/Format/TokenAnnotator.cpp +++ b/lib/Format/TokenAnnotator.cpp @@ -745,6 +745,11 @@ private: if (NextToken->is(tok::l_square)) return TT_PointerOrReference; + if (PrevToken->is(tok::r_paren) && PrevToken->MatchingParen && + PrevToken->MatchingParen->Previous && + PrevToken->MatchingParen->Previous->is(tok::kw_typeof)) + return TT_PointerOrReference; + if (PrevToken->Tok.isLiteral() || PrevToken->isOneOf(tok::r_paren, tok::r_square) || NextToken->Tok.isLiteral() || NextToken->isUnaryOperator()) diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index 8ae956e4fd..a27d193cb1 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -3765,6 +3765,7 @@ TEST_F(FormatTest, UnderstandsUsesOfStarAndAmp) { verifyIndependentOfContext("Type **A = static_cast(P);"); verifyGoogleFormat("Type** A = static_cast(P);"); verifyFormat("auto a = [](int **&, int ***) {};"); + verifyFormat("typedef typeof(int(int, int)) *MyFunc;"); verifyIndependentOfContext("InvalidRegions[*R] = 0;"); -- 2.40.0