return PeekAhead(N+1);
}
+ /// RevertCachedTokens - When backtracking is enabled and tokens are cached,
+ /// this allows to revert a specific number of tokens.
+ /// Note that the number of tokens being reverted should be up to the last
+ /// backtrack position, not more.
+ void RevertCachedTokens(unsigned N) {
+ assert(isBacktrackEnabled() &&
+ "Should only be called when tokens are cached for backtracking");
+ assert(signed(CachedLexPos) - signed(N) >= signed(BacktrackPositions.back())
+ && "Should revert tokens up to the last backtrack position, not more");
+ assert(signed(CachedLexPos) - signed(N) >= 0 &&
+ "Corrupted backtrack positions ?");
+ CachedLexPos -= N;
+ }
+
/// EnterToken - Enters a token in the token stream to be lexed next. If
/// BackTrack() is called afterwards, the token will remain at the insertion
/// point.
if (SS.isNotEmpty()) {
// A C++ scope specifier that isn't followed by a typename.
- // Push the current token back into the token stream and use an annotation
- // scope token for current token.
- PP.EnterToken(Tok);
+ // Push the current token back into the token stream (or revert it if it is
+ // cached) and use an annotation scope token for current token.
+ if (PP.isBacktrackEnabled())
+ PP.RevertCachedTokens(1);
+ else
+ PP.EnterToken(Tok);
Tok.setKind(tok::annot_cxxscope);
Tok.setAnnotationValue(SS.getScopeRep());
Tok.setAnnotationRange(SS.getRange());
CXXScopeSpec SS;
ParseCXXScopeSpecifier(SS);
- // Push the current token back into the token stream and use an annotation
- // scope token for current token.
- PP.EnterToken(Tok);
+ // Push the current token back into the token stream (or revert it if it is
+ // cached) and use an annotation scope token for current token.
+ if (PP.isBacktrackEnabled())
+ PP.RevertCachedTokens(1);
+ else
+ PP.EnterToken(Tok);
Tok.setKind(tok::annot_cxxscope);
Tok.setAnnotationValue(SS.getScopeRep());
Tok.setAnnotationRange(SS.getRange());
{ typedef A::C A; A::ax = 0; } // expected-error {{no member named 'ax'}}
{ typedef A::C A; A::cx = 0; }
}
+
+// make sure the following doesn't hit any asserts
+void f4(undef::C); // expected-error {{use of undeclared identifier 'undef'}} // expected-error {{expected ')'}} expected-error {{to match this '('}} // expected-error {{variable has incomplete type 'void'}}