From: Bruno Cardoso Lopes Date: Fri, 5 Feb 2016 19:36:39 +0000 (+0000) Subject: [Parser] Perform CachedTokens update dependent on token consumption X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=83c02698258871896f3f173531ad6c8660ea1377;p=clang [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 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@259910 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Parse/ParseTemplate.cpp b/lib/Parse/ParseTemplate.cpp index 9e68c4a15d..e6ce30a659 100644 --- a/lib/Parse/ParseTemplate.cpp +++ b/lib/Parse/ParseTemplate.cpp @@ -855,8 +855,12 @@ bool Parser::ParseGreaterThanInTemplateList(SourceLocation &RAngleLoc, 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) { diff --git a/test/Parser/objcxx14-protocol-in-template.mm b/test/Parser/objcxx14-protocol-in-template.mm new file mode 100644 index 0000000000..36da92e251 --- /dev/null +++ b/test/Parser/objcxx14-protocol-in-template.mm @@ -0,0 +1,15 @@ +// RUN: %clang_cc1 -fsyntax-only -verify -std=c++14 %s + +template class vector {}; +@protocol P @end + +// expected-no-diagnostics + +template void F(Functor functor) {} + +// Test protocol in template within lambda capture initializer context. +void z() { + id

x = 0; + (void)x; + F( [ x = vector>{} ] {} ); +}