Preprocessing directives (such as #include, import, etc.) are recognized first during preprocessing, and then text replacement macros are expanded. Therefore, text replacement macros cannot generate preprocessing directives.
Consider the following code:
#define INCLUDE include
#INCLUDE <vector>
This program is clearly nonsensical.
I believe that after preprocessing, genuinely valid "import" directives could be translated into "_import" (this identifier is reserved). Thus, if an "import" without an underscore prefix remains in the code after preprocessing, it indicates that it was generated
by text replacement macros.
For example:
#define EMP
EMP import m;
import std;
After preprocessing, it becomes:
import m; // Still uses "import", so it is erroneous
_import std; // Correct import directive
From: Std-Proposals <std-proposals-bounces@lists.isocpp.org> on behalf of Yrong via Std-Proposals <std-proposals@lists.isocpp.org>
Sent: Monday, September 22, 2025 0:39
To: std-proposals@lists.isocpp.org <std-proposals@lists.isocpp.org>
Cc: Yrong <yronglin777@gmail.com>
Subject: [std-proposals] Direct compile a file VS preprocessing the file first and compile the preprocessing output would generate different behaviour in c++20 modules
Hi experts,
I'm working on implement P1857R3 in clang.
Hubert provided an example:
```
typedef int import;
#define EMP
EMP import m;
```
If we directly compile this code snippet, due to the `import` identifier is not in the start of line, and according to the current wording of the standard, this is not a C++ import directive. But if
we preprocessing the file first and compile the preprocessing output would have different behavior than above:
Generated by clang:
```
# 1 "./main.cpp"
# 1 "<built-in>" 1
# 1 "<built-in>" 3
# 490 "<built-in>" 3
# 1 "<command line>" 1
# 1 "<built-in>" 2
# 1 "./main.cpp" 2
typedef int import;
import m;
```
The `import` identifier now at start of line, so it's c++ import directive.
Is this the expected behavior? Should we keep the behavior consistent in both cases?
Best regards,
Yihan