Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / clang / test / CXX / module / module.interface / p7.cpp
blob1572390f0d2899d17c8b5d88cf698060678e59db
1 // RUN: rm -rf %t
2 // RUN: mkdir -p %t
3 // RUN: split-file %s %t
4 //
5 // RUN: %clang_cc1 -std=c++20 %t/p7.cppm -emit-module-interface -o %t/p7.pcm
6 // RUN: %clang_cc1 -std=c++20 -fprebuilt-module-path=%t %t/Use.cpp -verify
8 //--- p7.cppm
9 export module p7;
10 struct reachable {
11 constexpr static int sv = 43;
12 int value = 44;
14 static int getValue() { return 43; }
15 int get() { return 44; }
17 template <typename T>
18 static bool templ_get(T t) { return false; }
19 typedef int typedef_type;
20 using using_type = int;
21 template <typename T>
22 using templ_using_type = int;
23 bool operator()() {
24 return false;
27 enum E { a,
28 b };
31 export auto getReachable() {
32 return reachable{};
35 export enum E1 { e1 };
36 enum E2 { e2 };
37 export using E2U = E2;
38 enum E3 { e3 };
39 export E3 func();
41 //--- Use.cpp
42 import p7;
43 void test() {
44 auto reachable = getReachable();
45 int a = decltype(reachable)::sv;
46 int b = decltype(reachable)::getValue();
47 int c = reachable.value;
48 int d = reachable.get();
49 int e = decltype(reachable)::a;
50 int f = reachable.templ_get(a);
51 typename decltype(reachable)::typedef_type g;
52 typename decltype(reachable)::using_type h;
53 typename decltype(reachable)::template templ_using_type<int> j;
54 auto value = reachable();
57 void test2() {
58 auto a = E1::e1; // OK, namespace-scope name E1 is visible and e1 is reachable
59 auto b = e1; // OK, namespace-scope name e1 is visible
60 auto c = E2::e2; // expected-error {{declaration of 'E2' must be imported from module}}
61 // expected-note@* {{declaration here is not visible}}
62 auto d = e2; // should be error, namespace-scope name e2 is not visible
63 auto e = E2U::e2; // OK, namespace-scope name E2U is visible and E2::e2 is reachable
64 auto f = E3::e3; // expected-error {{declaration of 'E3' must be imported from module 'p7' before it is required}}
65 // expected-note@* {{declaration here is not visible}}
66 auto g = e3; // should be error, namespace-scope name e3 is not visible
67 auto h = decltype(func())::e3; // OK, namespace-scope name f is visible and E3::e3 is reachable