Debian Codegraph @

gcc/testsuite/g++.dg/modules/internal-5_a.C

raw
1 // { dg-additional-options "-fmodules-ts -Wtemplate-names-tu-local" }
2 // { dg-module-cmi M }
3 // Ignore exposures in these cases
4
5 export module M;
6
7 namespace {
8 inline namespace ns {
9 struct internal_t {};
10 template <typename T> struct internal_tmpl_t {};
11
12 int internal_x;
13 void internal_ovl(int&) {}
14 void internal_ovl(internal_t) {}
15
16 template <typename T> void internal_tmpl() {}
17 }
18 }
19 export struct ok_inst_tag {};
20
21
22 // The function body for a non-inline function or function template
23 export void function() {
24 internal_t i {};
25 internal_tmpl_t<int> ii {};
26 internal_ovl(internal_x);
27 internal_tmpl<int>();
28 }
29
30 export template <typename T> void function_tmpl() {
31 internal_t i {};
32 internal_tmpl_t<T> ii {};
33 internal_ovl(internal_x);
34 internal_tmpl<T>();
35 }
36 template void function_tmpl<ok_inst_tag>();
37 template <> void function_tmpl<ok_inst_tag*>() {}
38
39
40 // The initializer for a (non-inline) variable or variable template
41 export int var
42 = (internal_t{}, internal_tmpl_t<int>{},
43 internal_ovl(internal_x), internal_tmpl<int>(), 0);
44
45 export template <typename T> int var_tmpl
46 = (internal_t{}, internal_tmpl_t<T>{},
47 internal_ovl(internal_x), internal_tmpl<T>(), 0);
48
49 template <typename T> int var_tmpl<T*> // { dg-warning "refers to TU-local entity" }
50 = (internal_t{}, internal_tmpl_t<T*>{},
51 internal_ovl(internal_x), internal_tmpl<T*>(), 0);
52
53 template int var_tmpl<ok_inst_tag>;
54 template <> int var_tmpl<ok_inst_tag*> = 0;
55
56 export int* ptr = &internal_x;
57 export template <typename T> int* ptr_tmpl = &internal_x; // { dg-warning "refers to TU-local entity" }
58
59 export int& constant_ref = internal_x;
60 static_assert (&constant_ref == &internal_x);
61
62 // Support exposures in inline vars with dynamic initialisers
63 export inline int dynamic_var = (internal_ovl(internal_x), 0);
64
65
66 // Friend declarations in a class definition
67 export struct klass { // { dg-bogus "TU-local" }
68 friend ns::internal_t;
69 friend ns::internal_tmpl_t<int>;
70 friend void ns::internal_ovl(int&);
71 friend void ns::internal_ovl(internal_t);
72 friend void ns::internal_tmpl<int>();
73
74 template <typename> friend struct ns::internal_tmpl_t;
75 template <typename> friend void ns::internal_tmpl();
76 };
77
78 export template <typename T>
79 class klass_tmpl { // { dg-bogus "TU-local" }
80 friend ns::internal_t;
81 friend ns::internal_tmpl_t<int>;
82 friend void ns::internal_ovl(int&);
83 friend void ns::internal_ovl(internal_t);
84 friend void ns::internal_tmpl<int>();
85
86 template <typename> friend struct ns::internal_tmpl_t;
87 template <typename> friend void ns::internal_tmpl();
88 };
89
90 template <typename T> class klass_tmpl<T*> { // { dg-bogus "TU-local" }
91 friend ns::internal_t;
92 friend ns::internal_tmpl_t<int>;
93 friend void ns::internal_ovl(int&);
94 friend void ns::internal_ovl(internal_t);
95 friend void ns::internal_tmpl<int>();
96
97 template <typename> friend struct ns::internal_tmpl_t;
98 template <typename> friend void ns::internal_tmpl();
99 };
100
101
102 // Any reference to a non-volatile const object or reference with internal or
103 // no linkage initialized with a constant expression that is not an ODR-use
104 static const int value = 123;
105 static const int& ref = 456;
106 static const internal_t internal {};
107 void f(int) {}
108 export inline void no_odr_use() {
109 int x = value;
110 int y = ref;
111 int z = (internal, 0);
112
113 value;
114 bool b = value < value;
115 f(value);
116 }