Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / clang / test / Modules / cxx20-10-2-ex5.cpp
blob49c5934c8f2172d14dc40d76c3ee6ae681df6a4f
1 // Based on C++20 10.2 example 5.
3 // RUN: rm -rf %t
4 // RUN: mkdir -p %t
5 // RUN: split-file %s %t
7 // RUN: %clang_cc1 -std=c++20 -emit-module-interface %t/std-10-2-ex5-tu1.cpp \
8 // RUN: -o %t/M.pcm
10 // RUN: %clang_cc1 -std=c++20 -emit-obj %t/std-10-2-ex5-tu2.cpp \
11 // RUN: -fmodule-file=M=%t/M.pcm -o %t/tu-2.o
13 // RUN: %clang_cc1 -std=c++20 -emit-obj %t/std-10-2-ex5-tu3.cpp \
14 // RUN: -fmodule-file=M=%t/M.pcm -verify -o %t/main.o
16 //--- std-10-2-ex5-tu1.cpp
17 export module M;
18 export struct X {
19 static void f();
20 struct Y {};
22 namespace {
23 struct S {};
24 } // namespace
25 export void f(S); // OK
26 struct T {};
27 export T id(T); // OK
28 export struct A; // A exported as incomplete
30 export auto rootFinder(double a) {
31 return [=](double x) { return (x + a / x) / 2; };
33 export const int n = 5; // OK, n has external linkage
35 //--- std-10-2-ex5-tu2.cpp
37 module M;
38 struct A {
39 int value;
42 //--- std-10-2-ex5-tu3.cpp
44 import M;
46 int main() {
47 X::f(); // OK, X is exported and definition of X is reachable
48 X::Y y; // OK, X::Y is exported as a complete type
49 auto f = rootFinder(2); // OK
50 // error: A is incomplete
51 return A{45}.value; // expected-error {{invalid use of incomplete type 'A'}}
52 // expected-error@-1 {{member access into incomplete type 'A'}}
53 // expected-note@std-10-2-ex5-tu1.cpp:12 2{{forward declaration of 'A'}}