blob: f222568072393f949dd0d3fe72ce701143d55bc3 [file] [log] [blame]
Iain Sandoef60dc3c2021-05-04 09:56:02 +01001// Based on C++20 10.2 example 5.
2
3// RUN: rm -rf %t
4// RUN: mkdir -p %t
5// RUN: split-file %s %t
6
7// RUN: %clang_cc1 -std=c++20 -emit-module-interface %t/std-10-2-ex5-tu1.cpp \
8// RUN: -o %t/M.pcm
9
10// RUN: %clang_cc1 -std=c++20 -emit-obj %t/std-10-2-ex5-tu2.cpp \
Chuanqi Xu57833632023-02-24 16:41:52 +080011// RUN: -fmodule-file=M=%t/M.pcm -o %t/tu-2.o
Iain Sandoef60dc3c2021-05-04 09:56:02 +010012
13// RUN: %clang_cc1 -std=c++20 -emit-obj %t/std-10-2-ex5-tu3.cpp \
Chuanqi Xu57833632023-02-24 16:41:52 +080014// RUN: -fmodule-file=M=%t/M.pcm -verify -o %t/main.o
Iain Sandoef60dc3c2021-05-04 09:56:02 +010015
Chuanqi Xuda00c602024-03-08 10:12:51 +080016// Test again with reduced BMI.
17// RUN: rm %t/M.pcm
18// RUN: %clang_cc1 -std=c++20 -emit-reduced-module-interface %t/std-10-2-ex5-tu1.cpp \
19// RUN: -o %t/M.pcm
20
21// RUN: %clang_cc1 -std=c++20 -emit-obj %t/std-10-2-ex5-tu2.cpp \
22// RUN: -fmodule-file=M=%t/M.pcm -o %t/tu-2.o
23
24// RUN: %clang_cc1 -std=c++20 -emit-obj %t/std-10-2-ex5-tu3.cpp \
25// RUN: -fmodule-file=M=%t/M.pcm -verify -o %t/main.o
26
27
Iain Sandoef60dc3c2021-05-04 09:56:02 +010028//--- std-10-2-ex5-tu1.cpp
29export module M;
30export struct X {
31 static void f();
32 struct Y {};
33};
34namespace {
35struct S {};
36} // namespace
37export void f(S); // OK
38struct T {};
39export T id(T); // OK
40export struct A; // A exported as incomplete
41
42export auto rootFinder(double a) {
43 return [=](double x) { return (x + a / x) / 2; };
44}
45export const int n = 5; // OK, n has external linkage
46
47//--- std-10-2-ex5-tu2.cpp
48
49module M;
50struct A {
51 int value;
52};
53
54//--- std-10-2-ex5-tu3.cpp
55
56import M;
57
58int main() {
59 X::f(); // OK, X is exported and definition of X is reachable
60 X::Y y; // OK, X::Y is exported as a complete type
61 auto f = rootFinder(2); // OK
62 // error: A is incomplete
63 return A{45}.value; // expected-error {{invalid use of incomplete type 'A'}}
64 // expected-error@-1 {{member access into incomplete type 'A'}}
65 // expected-note@std-10-2-ex5-tu1.cpp:12 2{{forward declaration of 'A'}}
66}