xref: /llvm-project/clang/test/CXX/module/module.interface/p1.cpp (revision 57833636816a13ccda53714413c532dc81e3b5ff)
1a5bbbfefSRichard Smith // RUN: %clang_cc1 -std=c++2a %s -DERRORS -verify
2a5bbbfefSRichard Smith // RUN: %clang_cc1 -std=c++2a %s -emit-module-interface -o %t.pcm
3*57833636SChuanqi Xu // RUN: %clang_cc1 -std=c++2a %s -fmodule-file=M=%t.pcm -DIMPLEMENTATION -verify -Db=b2 -Dc=c2
4a5bbbfefSRichard Smith 
5a5bbbfefSRichard Smith module;
6a5bbbfefSRichard Smith 
7a5bbbfefSRichard Smith #ifdef ERRORS
8999ead9dSChuanqi Xu export int a; // expected-error {{export declaration can only be used within a module purview}}
9a5bbbfefSRichard Smith #endif
10a5bbbfefSRichard Smith 
11a5bbbfefSRichard Smith #ifndef IMPLEMENTATION
12a5bbbfefSRichard Smith export
13a5bbbfefSRichard Smith #else
14999ead9dSChuanqi Xu // expected-error@#1 {{export declaration can only be used within a module purview}}
15999ead9dSChuanqi Xu // expected-error@#2 {{export declaration can only be used within a module purview}}
16a5bbbfefSRichard Smith // expected-note@+2 1+{{add 'export'}}
17a5bbbfefSRichard Smith #endif
18a5bbbfefSRichard Smith module M;
19a5bbbfefSRichard Smith 
20a5bbbfefSRichard Smith export int b; // #1
21a5bbbfefSRichard Smith namespace N {
22a5bbbfefSRichard Smith   export int c; // #2
23a5bbbfefSRichard Smith }
24a5bbbfefSRichard Smith 
25a5bbbfefSRichard Smith #ifdef ERRORS
26e181de7fSRichard Smith namespace { // expected-note 2{{anonymous namespace begins here}}
27e181de7fSRichard Smith   export int d1; // expected-error {{export declaration appears within anonymous namespace}}
28a5bbbfefSRichard Smith   namespace X {
29e181de7fSRichard Smith     export int d2; // expected-error {{export declaration appears within anonymous namespace}}
30a5bbbfefSRichard Smith   }
31a5bbbfefSRichard Smith }
32a5bbbfefSRichard Smith 
33a5bbbfefSRichard Smith export export int e; // expected-error {{within another export declaration}}
34e181de7fSRichard Smith export { export int f; } // expected-error {{within another export declaration}} expected-note {{export block begins here}}
35a5bbbfefSRichard Smith 
36a5bbbfefSRichard Smith module :private; // expected-note {{private module fragment begins here}}
37a5bbbfefSRichard Smith export int priv; // expected-error {{export declaration cannot be used in a private module fragment}}
38a5bbbfefSRichard Smith #endif
39