r210643 - clang-format: Fix pointer/reference detection after decltype.

Daniel Jasper djasper at google.com
Wed Jun 11 00:35:16 PDT 2014


Author: djasper
Date: Wed Jun 11 02:35:16 2014
New Revision: 210643

URL: http://llvm.org/viewvc/llvm-project?rev=210643&view=rev
Log:
clang-format: Fix pointer/reference detection after decltype.

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

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

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=210643&r1=210642&r2=210643&view=diff
==============================================================================
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Wed Jun 11 02:35:16 2014
@@ -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() ||

Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=210643&r1=210642&r2=210643&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Wed Jun 11 02:35:16 2014
@@ -4740,6 +4740,7 @@ TEST_F(FormatTest, UnderstandsUsesOfStar
   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();");





More information about the cfe-commits mailing list