================
@@ -2383,6 +2384,59 @@ class Preprocessor {
/// token.
std::optional<Token> peekNextPPToken() const;
+ /// Check whether the next preprocessing token can form a header-name token
+ /// or matches one of the specified token kinds.
+ ///
+ /// This performs a lookahead without consuming tokens:
+ /// - First, it temporarily enables `ParsingFilename` to attempt forming a
+ /// `tok::header_name` (e.g. `<foo>` or "foo").
+ /// - If that succeeds, returns true.
+ /// - Otherwise, it restores normal lexing mode and checks whether the next
+ /// token matches any of the provided kinds `Ks...`.
+ ///
+ /// This helper is used to classify tokens in contexts such as C++20 `import`
+ /// and `#include`, ensuring consistent handling of header-name lexing and
+ /// avoiding unintended lexer state changes.
+ template <typename... Ts> bool isNextPPTokenHeaderNameOrOneOf(Ts... Ks) {
+ // First, tries to form a valid header-name token.
+ llvm::SaveAndRestore<bool>
SavedParsingFilename(CurPPLexer->ParsingFilename,
+ true);
+ if (auto NextTok = peekNextPPToken()) {
----------------
yronglin wrote:
Thanks for the suggestion. Fixed.
https://github.com/llvm/llvm-project/pull/191004
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits