[clang] Implement lifetime analysis for lifetime_capture_by(X) (#115921)
[llvm-project.git] / clang / test / Modules / cxx20-10-5-ex1.cpp
blobe87f4b78a0be0cb8ad38762223a7fede440043f2
1 // RUN: rm -rf %t
2 // RUN: split-file %s %t
3 // RUN: cd %t
5 // RUN: %clang_cc1 -std=c++20 std-10-5-ex1-interface.cpp \
6 // RUN: -DBAD_FWD_DECL -fsyntax-only -verify
8 // RUN: %clang_cc1 -std=c++20 -emit-module-interface std-10-5-ex1-interface.cpp \
9 // RUN: -o A.pcm
11 // RUN: %clang_cc1 -std=c++20 std-10-5-ex1-use.cpp -fmodule-file=A=A.pcm \
12 // RUN: -fsyntax-only -verify
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
19 // RUN: %clang_cc1 -std=c++20 -emit-reduced-module-interface std-10-5-ex1-interface.cpp \
20 // RUN: -o A.pcm
22 // RUN: %clang_cc1 -std=c++20 std-10-5-ex1-use.cpp -fmodule-file=A=A.pcm \
23 // RUN: -fsyntax-only -verify
26 //--- std-10-5-ex1-interface.cpp
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
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;
41 export void g(X *x) {
42 fn_s();
44 export X *factory();
45 void ok_fn2() {}
47 module :private;
48 struct X {};
49 X *factory() {
50 return new X();
53 void fn_e() {}
54 void fn_m() {}
55 void fn_s() {}
57 //--- std-10-5-ex1-use.cpp
59 import A;
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();