Author: bruno Date: Fri Feb 5 13:36:39 2016 New Revision: 259910 URL: http://llvm.org/viewvc/llvm-project?rev=259910&view=rev Log: [Parser] Perform CachedTokens update dependent on token consumption
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 a not yet cached token. Differential Revision: http://reviews.llvm.org/D16906 rdar://problem/24488367 Added: cfe/trunk/test/Parser/objcxx14-protocol-in-template.mm Modified: cfe/trunk/lib/Parse/ParseTemplate.cpp Modified: cfe/trunk/lib/Parse/ParseTemplate.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseTemplate.cpp?rev=259910&r1=259909&r2=259910&view=diff ============================================================================== --- cfe/trunk/lib/Parse/ParseTemplate.cpp (original) +++ cfe/trunk/lib/Parse/ParseTemplate.cpp Fri Feb 5 13:36:39 2016 @@ -855,8 +855,12 @@ bool Parser::ParseGreaterThanInTemplateL 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) { Added: cfe/trunk/test/Parser/objcxx14-protocol-in-template.mm URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Parser/objcxx14-protocol-in-template.mm?rev=259910&view=auto ============================================================================== --- cfe/trunk/test/Parser/objcxx14-protocol-in-template.mm (added) +++ cfe/trunk/test/Parser/objcxx14-protocol-in-template.mm Fri Feb 5 13:36:39 2016 @@ -0,0 +1,15 @@ +// RUN: %clang_cc1 -fsyntax-only -verify -std=c++14 %s + +template<class T> class vector {}; +@protocol P @end + +// expected-no-diagnostics + +template <typename Functor> void F(Functor functor) {} + +// Test protocol in template within lambda capture initializer context. +void z() { + id<P> x = 0; + (void)x; + F( [ x = vector<id<P>>{} ] {} ); +} _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits