Index: lib/Lex/PPCaching.cpp =================================================================== --- lib/Lex/PPCaching.cpp +++ lib/Lex/PPCaching.cpp @@ -97,13 +97,33 @@ 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 case before checking the assertion. + if (CachedLastTokLoc != TokAnnEndLoc && !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. for (CachedTokensTy::size_type i = CachedLexPos; i != 0; --i) { - CachedTokensTy::iterator AnnotBegin = CachedTokens.begin() + i-1; + CachedTokensTy::iterator AnnotBegin = CachedTokens.begin() + i - 1; if (AnnotBegin->getLocation() == Tok.getLocation()) { assert((BacktrackPositions.empty() || BacktrackPositions.back() < i) && "The backtrack pos points inside the annotated tokens!"); 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);