Debian Codegraph @

clang/test/SemaTemplate/undefined-template.cpp

raw
1 // RUN: %clang_cc1 -fsyntax-only -verify -std=c++14 -Wundefined-func-template %s
2
3 #if !defined(INCLUDE)
4 template <class T> struct C1 {
5 static char s_var_1; // expected-note{{forward declaration of template entity is here}}
6 static char s_var_2; // expected-note{{forward declaration of template entity is here}}
7 static void s_func_1(); // expected-note{{forward declaration of template entity is here}}
8 static void s_func_2(); // expected-note{{forward declaration of template entity is here}}
9 void meth_1(); // expected-note2{{forward declaration of template entity is here}}
10 void meth_2();
11 template <class T1> static char s_tvar_2; // expected-note{{forward declaration of template entity is here}}
12 template <class T1> static void s_tfunc_2(); // expected-note{{forward declaration of template entity is here}}
13 template<typename T1> struct C2 {
14 static char s_var_2; // expected-note{{forward declaration of template entity is here}}
15 static void s_func_2(); // expected-note{{forward declaration of template entity is here}}
16 void meth_2(); // expected-note{{forward declaration of template entity is here}}
17 template <class T2> static char s_tvar_2; // expected-note{{forward declaration of template entity is here}}
18 template <class T2> void tmeth_2(); // expected-note{{forward declaration of template entity is here}}
19 };
20 };
21
22 extern template char C1<int>::s_var_2;
23 extern template void C1<int>::s_func_2();
24 extern template void C1<int>::meth_2();
25 extern template char C1<int>::s_tvar_2<char>;
26 extern template void C1<int>::s_tfunc_2<char>();
27 extern template void C1<int>::C2<long>::s_var_2;
28 extern template void C1<int>::C2<long>::s_func_2();
29 extern template void C1<int>::C2<long>::meth_2();
30 extern template char C1<int>::C2<long>::s_tvar_2<char>;
31 extern template void C1<int>::C2<long>::tmeth_2<char>();
32
33 char func_01() {
34 return C1<int>::s_var_2;
35 }
36
37 char func_02() {
38 return C1<int>::s_var_1; // expected-warning{{instantiation of variable 'C1<int>::s_var_1' required here, but no definition is available}}
39 // expected-note@-1{{add an explicit instantiation declaration to suppress this warning if 'C1<int>::s_var_1' is explicitly instantiated in another translation unit}}
40 }
41
42 char func_03() {
43 return C1<char>::s_var_2; // expected-warning{{instantiation of variable 'C1<char>::s_var_2' required here, but no definition is available}}
44 // expected-note@-1{{add an explicit instantiation declaration to suppress this warning if 'C1<char>::s_var_2' is explicitly instantiated in another translation unit}}
45 }
46
47 void func_04() {
48 C1<int>::s_func_1(); // expected-warning{{instantiation of function 'C1<int>::s_func_1' required here, but no definition is available}}
49 // expected-note@-1{{add an explicit instantiation declaration to suppress this warning if 'C1<int>::s_func_1' is explicitly instantiated in another translation unit}}
50 }
51
52 void func_05() {
53 C1<int>::s_func_2();
54 }
55
56 void func_06() {
57 C1<char>::s_func_2(); // expected-warning{{instantiation of function 'C1<char>::s_func_2' required here, but no definition is available}}
58 // expected-note@-1{{add an explicit instantiation declaration to suppress this warning if 'C1<char>::s_func_2' is explicitly instantiated in another translation unit}}
59 }
60
61 void func_07(C1<int> *x) {
62 x->meth_1(); // expected-warning{{instantiation of function 'C1<int>::meth_1' required here, but no definition is available}}
63 // expected-note@-1{{add an explicit instantiation declaration to suppress this warning if 'C1<int>::meth_1' is explicitly instantiated in another translation unit}}
64 }
65
66 void func_08(C1<int> *x) {
67 x->meth_2();
68 }
69
70 void func_09(C1<char> *x) {
71 x->meth_1(); // expected-warning{{instantiation of function 'C1<char>::meth_1' required here, but no definition is available}}
72 // expected-note@-1{{add an explicit instantiation declaration to suppress this warning if 'C1<char>::meth_1' is explicitly instantiated in another translation unit}}
73 }
74
75 char func_10() {
76 return C1<int>::s_tvar_2<char>;
77 }
78
79 char func_11() {
80 return C1<int>::s_tvar_2<long>; // expected-warning{{instantiation of variable 'C1<int>::s_tvar_2<long>' required here, but no definition is available}}
81 // expected-note@-1{{add an explicit instantiation declaration to suppress this warning if 'C1<int>::s_tvar_2<long>' is explicitly instantiated in another translation unit}}
82 }
83
84 void func_12() {
85 C1<int>::s_tfunc_2<char>();
86 }
87
88 void func_13() {
89 C1<int>::s_tfunc_2<long>(); // expected-warning{{instantiation of function 'C1<int>::s_tfunc_2<long>' required here, but no definition is available}}
90 // expected-note@-1{{add an explicit instantiation declaration to suppress this warning if 'C1<int>::s_tfunc_2<long>' is explicitly instantiated in another translation unit}}
91 }
92
93 char func_14() {
94 return C1<int>::C2<long>::s_var_2;
95 }
96
97 char func_15() {
98 return C1<int>::C2<char>::s_var_2; //expected-warning {{instantiation of variable 'C1<int>::C2<char>::s_var_2' required here, but no definition is available}}
99 // expected-note@-1{{add an explicit instantiation declaration to suppress this warning if 'C1<int>::C2<char>::s_var_2' is explicitly instantiated in another translation unit}}
100 }
101
102 void func_16() {
103 C1<int>::C2<long>::s_func_2();
104 }
105
106 void func_17() {
107 C1<int>::C2<char>::s_func_2(); // expected-warning{{instantiation of function 'C1<int>::C2<char>::s_func_2' required here, but no definition is available}}
108 // expected-note@-1{{add an explicit instantiation declaration to suppress this warning if 'C1<int>::C2<char>::s_func_2' is explicitly instantiated in another translation unit}}
109 }
110
111 void func_18(C1<int>::C2<long> *x) {
112 x->meth_2();
113 }
114
115 void func_19(C1<int>::C2<char> *x) {
116 x->meth_2(); // expected-warning{{instantiation of function 'C1<int>::C2<char>::meth_2' required here, but no definition is available}}
117 // expected-note@-1{{add an explicit instantiation declaration to suppress this warning if 'C1<int>::C2<char>::meth_2' is explicitly instantiated in another translation unit}}
118 }
119
120 char func_20() {
121 return C1<int>::C2<long>::s_tvar_2<char>;
122 }
123
124 char func_21() {
125 return C1<int>::C2<long>::s_tvar_2<long>; // expected-warning{{instantiation of variable 'C1<int>::C2<long>::s_tvar_2<long>' required here, but no definition is available}}
126 // expected-note@-1{{add an explicit instantiation declaration to suppress this warning if 'C1<int>::C2<long>::s_tvar_2<long>' is explicitly instantiated in another translation unit}}
127 }
128
129 void func_22(C1<int>::C2<long> *x) {
130 x->tmeth_2<char>();
131 }
132
133 void func_23(C1<int>::C2<long> *x) {
134 x->tmeth_2<int>(); // expected-warning{{instantiation of function 'C1<int>::C2<long>::tmeth_2<int>' required here, but no definition is available}}
135 // expected-note@-1{{add an explicit instantiation declaration to suppress this warning if 'C1<int>::C2<long>::tmeth_2<int>' is explicitly instantiated in another translation unit}}
136 }
137
138 namespace test_24 {
139 template <typename T> struct X {
140 friend void g(int);
141 operator int() { return 0; }
142 };
143 void h(X<int> x) { g(x); } // no warning for use of 'g' despite the declaration having been instantiated from a template
144 }
145
146 #define INCLUDE
147 #include "undefined-template.cpp"
148 void func_25(SystemHeader<char> *x) {
149 x->meth();
150 }
151
152 int main() {
153 return 0;
154 }
155 #else
156 #pragma clang system_header
157 template <typename T> struct SystemHeader { T meth(); };
158 #endif