clang-format: Fix pointer/reference detection after decltype.
authorDaniel Jasper <djasper@google.com>
Wed, 11 Jun 2014 07:35:16 +0000 (07:35 +0000)
committerDaniel Jasper <djasper@google.com>
Wed, 11 Jun 2014 07:35:16 +0000 (07:35 +0000)
Before:
  [](const decltype(*a) & value) {}

After:
  [](const decltype(*a)& value) {}

llvm-svn: 210643

clang/lib/Format/TokenAnnotator.cpp
clang/unittests/Format/FormatTest.cpp

index 66060f0..f92a8f0 100644 (file)
@@ -921,7 +921,8 @@ private:
 
     if (PrevToken->is(tok::r_paren) && PrevToken->MatchingParen &&
         PrevToken->MatchingParen->Previous &&
-        PrevToken->MatchingParen->Previous->is(tok::kw_typeof))
+        PrevToken->MatchingParen->Previous->isOneOf(tok::kw_typeof,
+                                                    tok::kw_decltype))
       return TT_PointerOrReference;
 
     if (PrevToken->Tok.isLiteral() ||
index a923e1a..f474c42 100644 (file)
@@ -4740,6 +4740,7 @@ TEST_F(FormatTest, UnderstandsUsesOfStarAndAmp) {
   verifyFormat("auto a = [](int **&, int ***) {};");
   verifyFormat("auto PointerBinding = [](const char *S) {};");
   verifyFormat("typedef typeof(int(int, int)) *MyFunc;");
+  verifyFormat("[](const decltype(*a) &value) {}");
   verifyIndependentOfContext("typedef void (*f)(int *a);");
   verifyIndependentOfContext("int i{a * b};");
   verifyIndependentOfContext("aaa && aaa->f();");