C++ Logo

std-proposals

Advanced search

[std-proposals] Direct compile a file VS preprocessing the file first and compile the preprocessing output would generate different behaviour in c++20 modules

From: Yrong <yronglin777_at_[hidden]>
Date: Mon, 22 Sep 2025 00:39:18 +0800
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

Received on 2025-09-21 16:39:31