r190401 - clang-format: Understand function type typedefs with typeof.
Daniel Jasper
djasper at google.com
Tue Sep 10 03:26:39 PDT 2013
Author: djasper
Date: Tue Sep 10 05:26:38 2013
New Revision: 190401
URL: http://llvm.org/viewvc/llvm-project?rev=190401&view=rev
Log:
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.
Modified:
cfe/trunk/lib/Format/TokenAnnotator.cpp
cfe/trunk/unittests/Format/FormatTest.cpp
Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=190401&r1=190400&r2=190401&view=diff
==============================================================================
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Tue Sep 10 05:26:38 2013
@@ -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())
Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=190401&r1=190400&r2=190401&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Tue Sep 10 05:26:38 2013
@@ -3765,6 +3765,7 @@ TEST_F(FormatTest, UnderstandsUsesOfStar
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;");
More information about the cfe-commits
mailing list