[clang] [clang][Preprocessor] Add peekNextPPToken, makes look ahead next token without side-effects (PR #143898)

Aaron Ballman via cfe-commits cfe-commits at lists.llvm.org
Thu Jun 12 08:54:41 PDT 2025


================
@@ -2288,7 +2288,9 @@ class Preprocessor {
   /// Determine whether the next preprocessor token to be
   /// lexed is a '('.  If so, consume the token and return true, if not, this
   /// method should have no observable side-effect on the lexed tokens.
-  bool isNextPPTokenLParen();
+  bool isNextPPTokenLParen() {
+    return peekNextPPToken().value_or(Token{}).is(tok::l_paren);
----------------
AaronBallman wrote:

The lexer is almost always on the hot path but `Token`s are small... I think it may be worth verifying that this has no performance difference from an approach without `value_or`.

https://github.com/llvm/llvm-project/pull/143898


More information about the cfe-commits mailing list