[PATCH] D16906: [Parser] Perform CachedTokens update dependent on token consume request

Bruno Cardoso Lopes via cfe-commits cfe-commits at lists.llvm.org
Thu Feb 4 16:27:52 PST 2016


bruno created this revision.
bruno added reviewers: rsmith, doug.gregor, akyrtzi.
bruno added subscribers: cfe-commits, dexonsmith.

In the context where we break one tok::greatergreater into two tok::greater in order to correctly update the cached tokens; update the CachedTokens with two tok::greater only if ParseGreaterThanInTemplateList clients asks to consume the last token. Otherwise we only need to add one because the second is already added later on, as the current token.

This is a follow up from r259311.

http://reviews.llvm.org/D16906

Files:
  lib/Parse/ParseTemplate.cpp
  test/Parser/objcxx11-protocol-in-template.mm

Index: test/Parser/objcxx11-protocol-in-template.mm
===================================================================
--- test/Parser/objcxx11-protocol-in-template.mm
+++ test/Parser/objcxx11-protocol-in-template.mm
@@ -16,3 +16,11 @@
 typedef int some_t;
 
 id<PA> FA(NSArray<id<PB>> *h, some_t group);
+
+template <typename Functor> void F(Functor functor) {}
+
+void z() {
+  id<P> x = 0;
+  (void)x;
+  F( [ x = vector<id<P>>{} ] {} );
+}
Index: lib/Parse/ParseTemplate.cpp
===================================================================
--- lib/Parse/ParseTemplate.cpp
+++ lib/Parse/ParseTemplate.cpp
@@ -855,8 +855,12 @@
       RemainingToken == tok::greater && PP.IsPreviousCachedToken(PrevTok)) {
     PrevTok.setKind(RemainingToken);
     PrevTok.setLength(1);
-    Token NewToks[] = {PrevTok, Tok};
-    PP.ReplacePreviousCachedToken(NewToks);
+    // Break tok::greatergreater into two tok::greater but only add the second
+    // one in case the client asks to consume the last token.
+    if (ConsumeLastToken)
+      PP.ReplacePreviousCachedToken({PrevTok, Tok});
+    else
+      PP.ReplacePreviousCachedToken({PrevTok});
   }
 
   if (!ConsumeLastToken) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D16906.46978.patch
Type: text/x-patch
Size: 1178 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160205/318e420f/attachment.bin>


More information about the cfe-commits mailing list