C++ Logo

std-proposals

Advanced search

Re: [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 01:26:39 +0800
At the start of phase 4 an import or module token is treated as starting a
directive and are converted to their respective keywords. and import/module
statement handled in phase 4.
FYI: https://github.com/llvm/llvm-project/pull/107168.

Best regards,
Yihan

Andre Kostur <andre_at_[hidden]> 于2025年9月22日周一 01:00写道:

> Doesn't preprocessing happen before trying to understand the import
> statement? Or to rephrase: during which translation phase is the
> import statement handled?
>
> On Sun, Sep 21, 2025 at 9:39 AM Yrong via Std-Proposals
> <std-proposals_at_[hidden]> wrote:
> >
> > 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
> >
> > --
> > Std-Proposals mailing list
> > Std-Proposals_at_[hidden]
> > https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
>

Received on 2025-09-21 17:26:52