diff options
author | Daniel Jasper <djasper@google.com> | 2013-09-10 10:26:38 +0000 |
---|---|---|
committer | Daniel Jasper <djasper@google.com> | 2013-09-10 10:26:38 +0000 |
commit | 71665cd1fdf281cfcbbe3a3f91623ddd50bf6551 (patch) | |
tree | 9dffb37f580cbfdf7de1def8f541dd552a06b536 | |
parent | a9eb9972e4183bc859d6daf16ab32b855c196f4e (diff) | |
download | bcm5719-llvm-71665cd1fdf281cfcbbe3a3f91623ddd50bf6551.tar.gz bcm5719-llvm-71665cd1fdf281cfcbbe3a3f91623ddd50bf6551.zip |
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.
llvm-svn: 190401
-rw-r--r-- | clang/lib/Format/TokenAnnotator.cpp | 5 | ||||
-rw-r--r-- | clang/unittests/Format/FormatTest.cpp | 1 |
2 files changed, 6 insertions, 0 deletions
diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp index c0897ca68cb..d9aef602d3f 100644 --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/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/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index 8ae956e4fd2..a27d193cb19 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -3765,6 +3765,7 @@ TEST_F(FormatTest, UnderstandsUsesOfStarAndAmp) { verifyIndependentOfContext("Type **A = static_cast<Type **>(P);"); verifyGoogleFormat("Type** A = static_cast<Type**>(P);"); verifyFormat("auto a = [](int **&, int ***) {};"); + verifyFormat("typedef typeof(int(int, int)) *MyFunc;"); verifyIndependentOfContext("InvalidRegions[*R] = 0;"); |