• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // RUN: %clang_cc1 -fsyntax-only -verify %s
2 // RUN: %clang_cc1 -fsyntax-only -verify -std=c++98 %s
3 // RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
4 
5 struct C { };
6 
7 template<typename T>
8 struct X0 {
9   T value; // expected-error{{incomplete}}
10 };
11 
12 // Explicitly instantiate a class template specialization
13 template struct X0<int>;
14 template struct X0<void>; // expected-note{{instantiation}}
15 
16 // Explicitly instantiate a function template specialization
17 template<typename T>
f0(T t)18 void f0(T t) {
19   ++t; // expected-error{{cannot increment}}
20 }
21 
22 template void f0(int);
23 template void f0<long>(long);
24 template void f0<>(unsigned);
25 template void f0(int C::*); // expected-note{{instantiation}}
26 
27 // Explicitly instantiate a member template specialization
28 template<typename T>
29 struct X1 {
30   template<typename U>
31   struct Inner {
32     T member1;
33     U member2; // expected-error{{incomplete}}
34   };
35 
36   template<typename U>
fX137   void f(T& t, U u) {
38     t = u; // expected-error{{incompatible}}
39   }
40 };
41 
42 template struct X1<int>::Inner<float>;
43 template struct X1<int>::Inner<double>;
44 template struct X1<int>::Inner<void>; // expected-note{{instantiation}}
45 
46 template void X1<int>::f(int&, float);
47 template void X1<int>::f<long>(int&, long);
48 template void X1<int>::f<>(int&, double);
49 template void X1<int>::f<>(int&, int*); // expected-note{{instantiation}}
50 
51 // Explicitly instantiate members of a class template
52 struct Incomplete; // expected-note{{forward declaration}}
53 struct NonDefaultConstructible { // expected-note{{candidate constructor (the implicit copy constructor) not viable}}
54 #if __cplusplus >= 201103L // C++11 or later
55 // expected-note@-2 {{candidate constructor (the implicit move constructor) not viable}}
56 #endif
57   NonDefaultConstructible(int); // expected-note{{candidate constructor}}
58 };
59 
60 template<typename T, typename U>
61 struct X2 {
fX262   void f(T &t, U u) {
63     t = u; // expected-error{{incompatible}}
64   }
65 
66   struct Inner {
67     T member1;
68     U member2; // expected-error{{incomplete}}
69   };
70 
71   static T static_member1;
72   static U static_member2;
73 };
74 
75 template<typename T, typename U>
76 T X2<T, U>::static_member1 = 17; // expected-error{{cannot initialize}}
77 
78 template<typename T, typename U>
79 U X2<T, U>::static_member2; // expected-error{{no matching}}
80 
81 template void X2<int, float>::f(int &, float);
82 template void X2<int, float>::f(int &, double); // expected-error{{does not refer}}
83 template void X2<int, int*>::f(int&, int*); // expected-note{{instantiation}}
84 
85 template struct X2<int, float>::Inner;
86 template struct X2<int, Incomplete>::Inner; // expected-note{{instantiation}}
87 
88 template int X2<int, float>::static_member1;
89 template int* X2<int*, float>::static_member1; // expected-note{{instantiation}}
90 template
91   NonDefaultConstructible X2<NonDefaultConstructible, int>::static_member1;
92 
93 template
94   NonDefaultConstructible X2<int, NonDefaultConstructible>::static_member2; // expected-note{{instantiation}}
95