]> granicus.if.org Git - clang/commitdiff
clang-format: Understand function type typedefs with typeof.
authorDaniel Jasper <djasper@google.com>
Tue, 10 Sep 2013 10:26:38 +0000 (10:26 +0000)
committerDaniel Jasper <djasper@google.com>
Tue, 10 Sep 2013 10:26:38 +0000 (10:26 +0000)
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
unittests/Format/FormatTest.cpp

index c0897ca68cbe24697a26c5379a80187e40a22a86..d9aef602d3f811c49417096af024f1541c7295d6 100644 (file)
@@ -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())
index 8ae956e4fd2f7e1a45ecf92554fb71a9ee3a10c1..a27d193cb19ab5732eecba931ce0bd41292aa9b1 100644 (file)
@@ -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;");