Index: lib/Lex/PPCaching.cpp =================================================================== --- lib/Lex/PPCaching.cpp +++ lib/Lex/PPCaching.cpp @@ -97,8 +97,26 @@ void Preprocessor::AnnotatePreviousCachedTokens(const Token &Tok) { assert(Tok.isAnnotation() && "Expected annotation token"); assert(CachedLexPos != 0 && "Expected to have some cached tokens"); - assert(CachedTokens[CachedLexPos-1].getLastLoc() == Tok.getAnnotationEndLoc() - && "The annotation should be until the most recent cached token"); + +#ifndef NDEBUG + Token CachedLastTok = CachedTokens[CachedLexPos - 1]; + SourceLocation CachedLastTokLoc = CachedLastTok.getLastLoc(); + SourceLocation TokAnnEndLoc = Tok.getAnnotationEndLoc(); + + // The annotation should be until the most recent cached token. Since + // `Tok` length could be bigger than one (e.g. greatergreater '>>'), account + // for that cases before checking the assertion. + if (!CachedLastTok.isAnnotation()) { + CachedLastTokLoc = + CachedLastTokLoc.getLocWithOffset(CachedLastTok.getLength()); + unsigned TokAnnEndLocSize = Lexer::MeasureTokenLength( + SourceMgr.getSpellingLoc(TokAnnEndLoc), SourceMgr, LangOpts); + TokAnnEndLoc = TokAnnEndLoc.getLocWithOffset(TokAnnEndLocSize); + } + + assert(CachedLastTokLoc == TokAnnEndLoc && + "The annotation should be until the most recent cached token"); +#endif // Start from the end of the cached tokens list and look for the token // that is the beginning of the annotation token. Index: test/Parser/objcxx11-protocol-in-template.mm =================================================================== --- test/Parser/objcxx11-protocol-in-template.mm +++ test/Parser/objcxx11-protocol-in-template.mm @@ -8,3 +8,11 @@ vector> v; vector>> v2; + +@protocol PA; +@protocol PB; + +@class NSArray; +typedef int some_t; + +id FA(NSArray> *h, some_t group);