blob: 52530e2e3909a084c3b784f89c4b192eae18a5af [file] [log] [blame]
Serge Pavlov7dcc97e2016-04-19 06:19:52 +00001// RUN: %clang_cc1 -fsyntax-only -verify -std=c++14 -Wundefined-func-template %s
2
Nick Lewycky2adab1b2018-01-02 19:10:12 +00003#if !defined(INCLUDE)
Serge Pavlov7dcc97e2016-04-19 06:19:52 +00004template <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
22extern template char C1<int>::s_var_2;
23extern template void C1<int>::s_func_2();
24extern template void C1<int>::meth_2();
25extern template char C1<int>::s_tvar_2<char>;
26extern template void C1<int>::s_tfunc_2<char>();
27extern template void C1<int>::C2<long>::s_var_2;
28extern template void C1<int>::C2<long>::s_func_2();
29extern template void C1<int>::C2<long>::meth_2();
30extern template char C1<int>::C2<long>::s_tvar_2<char>;
31extern template void C1<int>::C2<long>::tmeth_2<char>();
32
33char func_01() {
34 return C1<int>::s_var_2;
35}
36
37char 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
42char 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
47void 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
52void func_05() {
53 C1<int>::s_func_2();
54}
55
56void 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
61void 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
66void func_08(C1<int> *x) {
67 x->meth_2();
68}
69
70void 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
75char func_10() {
76 return C1<int>::s_tvar_2<char>;
77}
78
79char 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
84void func_12() {
85 C1<int>::s_tfunc_2<char>();
86}
87
88void 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
93char func_14() {
94 return C1<int>::C2<long>::s_var_2;
95}
96
97char 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
102void func_16() {
103 C1<int>::C2<long>::s_func_2();
104}
105
106void 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
111void func_18(C1<int>::C2<long> *x) {
112 x->meth_2();
113}
114
115void 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
120char func_20() {
121 return C1<int>::C2<long>::s_tvar_2<char>;
122}
123
124char 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
129void func_22(C1<int>::C2<long> *x) {
130 x->tmeth_2<char>();
131}
132
133void 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
Richard Smithcfa5dc42017-01-28 01:50:33 +0000138namespace 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
Nick Lewycky2adab1b2018-01-02 19:10:12 +0000146#define INCLUDE
147#include "undefined-template.cpp"
148void func_25(SystemHeader<char> *x) {
149 x->meth();
150}
151
Serge Pavlov7dcc97e2016-04-19 06:19:52 +0000152int main() {
153 return 0;
154}
Nick Lewycky2adab1b2018-01-02 19:10:12 +0000155#else
156#pragma clang system_header
157template <typename T> struct SystemHeader { T meth(); };
158#endif