[clang] [clang] Fix incorrect uses header-name lexing rules when #include is followed by an empty macro expansion (PR #225451)
Yihan Wang via cfe-commits
cfe-commits at lists.llvm.org
Mon Sep 28 01:49:31 PDT 2026
================
----------------
yronglin wrote:
> It might be simpler and more correct to remove the `ParsingFilename` flag entirely, and instead call into a different lexing routine here that does the horizontal whitespace skipping then filename handling for a token starting with `<` or `"`, and otherwise just invokes the normal lexer. The approach in this PR only handles the case where a macro results in the filename not immediately following the introducing token, but not other cases such as:
>
> ```c++
> #include _Pragma("") "foo\"bar\".h"
> ```
>
> (I don't know if we _should_ allow empty `_Pragma`s -- or in general, pragmas that don't inject tokens -- there, but we do allow them _after_ the filename, and we're supposed to be applying the same rules in both places.)
Does C++20 `import` also follows this rule?
[[cpp.pre]/2.2](https://eel.is/c++draft/cpp.pre#2.2):
an import preprocessing token immediately followed on the same logical source line by a [header-name](https://eel.is/c++draft/lex.header#nt:header-name), <, [identifier](https://eel.is/c++draft/lex.name#nt:identifier), or : preprocessing token, or...
Does the following is a valid import directive?
```cpp
import EMPTY "foo.h";
```
https://github.com/llvm/llvm-project/pull/225451
More information about the cfe-commits
mailing list