Files
clang-p2996/clang/test/CXX/basic/basic.link/p2.cpp
yronglin ea321392eb [C++][Modules] A module directive may only appear as the first preprocessing tokens in a file (#144233)
This PR is 2nd part of
[P1857R3](https://github.com/llvm/llvm-project/pull/107168)
implementation, and mainly implement the restriction `A module directive
may only appear as the first preprocessing tokens in a file (excluding
the global module fragment.)`:
[cpp.pre](https://eel.is/c++draft/cpp.pre):
```
module-file:
    pp-global-module-fragment[opt] pp-module group[opt] pp-private-module-fragment[opt]
```

We also refine tests use `split-file` instead of conditional macro.

Signed-off-by: yronglin <yronglin777@gmail.com>
2025-06-21 18:58:56 +08:00

17 lines
548 B
C++

// RUN: rm -rf %t
// RUN: split-file %s %t
// RUN: %clang_cc1 -std=c++2a %t/pmf_in_interface.cpp -verify
// RUN: %clang_cc1 -std=c++2a %t/pmf_in_interface.cpp -emit-module-interface -o %t.pcm
// RUN: %clang_cc1 -std=c++2a %t/pmf_in_implementation.cpp -verify -fmodule-file=M=%t.pcm
//--- pmf_in_interface.cpp
// expected-no-diagnostics
export module M;
module :private;
//--- pmf_in_implementation.cpp
module M; // expected-note {{add 'export' here}}
module :private; // expected-error {{private module fragment in module implementation unit}}