xref: /llvm-project/clang/test/Modules/cxx20-10-5-ex1.cpp (revision 7e59223ac4b045178c287a56154113d5989572f4)
1 // RUN: rm -rf %t
2 // RUN: split-file %s %t
3 // RUN: cd %t
4 
5 // RUN: %clang_cc1 -std=c++20 std-10-5-ex1-interface.cpp \
6 // RUN: -DBAD_FWD_DECL  -fsyntax-only -verify
7 
8 // RUN: %clang_cc1 -std=c++20 -emit-module-interface std-10-5-ex1-interface.cpp \
9 // RUN: -o A.pcm
10 
11 // RUN: %clang_cc1 -std=c++20 std-10-5-ex1-use.cpp -fmodule-file=A=A.pcm \
12 // RUN:    -fsyntax-only -verify
13 
14 // Test again with reduced BMI.
15 // RUN: rm A.pcm
16 // RUN: %clang_cc1 -std=c++20 std-10-5-ex1-interface.cpp \
17 // RUN: -DBAD_FWD_DECL  -fsyntax-only -verify
18 
19 // RUN: %clang_cc1 -std=c++20 -emit-reduced-module-interface std-10-5-ex1-interface.cpp \
20 // RUN: -o A.pcm
21 
22 // RUN: %clang_cc1 -std=c++20 std-10-5-ex1-use.cpp -fmodule-file=A=A.pcm \
23 // RUN:    -fsyntax-only -verify
24 
25 
26 //--- std-10-5-ex1-interface.cpp
27 
28 export module A;
29 #ifdef BAD_FWD_DECL
30 export inline void fn_e(); // expected-error {{inline function not defined before the private module fragment}}
31                            // expected-note@std-10-5-ex1-interface.cpp:21 {{private module fragment begins here}}
32 #endif
ok_fn()33 export inline void ok_fn() {}
34 export inline void ok_fn2();
35 #ifdef BAD_FWD_DECL
36 inline void fn_m(); // expected-error {{inline function not defined before the private module fragment}}
37                     // expected-note@std-10-5-ex1-interface.cpp:21 {{private module fragment begins here}}
38 #endif
39 static void fn_s();
40 export struct X;
g(X * x)41 export void g(X *x) {
42   fn_s();
43 }
44 export X *factory();
ok_fn2()45 void ok_fn2() {}
46 
47 module :private;
48 struct X {};
factory()49 X *factory() {
50   return new X();
51 }
52 
fn_e()53 void fn_e() {}
fn_m()54 void fn_m() {}
fn_s()55 void fn_s() {}
56 
57 //--- std-10-5-ex1-use.cpp
58 
59 import A;
60 
foo()61 void foo() {
62   X x; // expected-error 1+{{missing '#include'; 'X' must be defined before it is used}}
63        // expected-note@std-10-5-ex1-interface.cpp:22 1+{{definition here is not reachable}}
64   X *p = factory();
65 }
66