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) {


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) {
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to