blob: 227856f1a8e22d08ec019a8f45cc33d5327f4757 [file] [log] [blame]
Daniel Dunbara5728872009-12-15 20:14:24 +00001// RUN: %clang_cc1 -fsyntax-only -verify %s
Douglas Gregord5a423b2009-09-25 18:43:00 +00002
3template void *; // expected-error{{expected unqualified-id}}
4
5template typedef void f0; // expected-error{{explicit instantiation of typedef}}
6
7int v0; // expected-note{{refers here}}
8template int v0; // expected-error{{does not refer}}
9
10template<typename T>
11struct X0 {
12 static T value;
13
14 T f0(T x) {
15 return x + 1; // expected-error{{invalid operands}}
16 }
Douglas Gregor558c0322009-10-14 23:41:34 +000017 T* f0(T*, T*) { return T(); }
Douglas Gregord5a423b2009-09-25 18:43:00 +000018
19 template<typename U>
Douglas Gregor558c0322009-10-14 23:41:34 +000020 T f0(T, U) { return T(); }
Douglas Gregord5a423b2009-09-25 18:43:00 +000021};
22
Douglas Gregor558c0322009-10-14 23:41:34 +000023template<typename T>
24T X0<T>::value; // expected-error{{no matching constructor}}
25
Douglas Gregord5a423b2009-09-25 18:43:00 +000026template int X0<int>::value;
27
John McCall220ccbf2010-01-13 00:25:19 +000028struct NotDefaultConstructible { // expected-note{{candidate constructor (the implicit copy constructor)}}
John McCallb1622a12010-01-06 09:43:14 +000029 NotDefaultConstructible(int); // expected-note{{candidate constructor}}
Douglas Gregord5a423b2009-09-25 18:43:00 +000030};
31
Douglas Gregor558c0322009-10-14 23:41:34 +000032template NotDefaultConstructible X0<NotDefaultConstructible>::value; // expected-note{{instantiation}}
Douglas Gregord5a423b2009-09-25 18:43:00 +000033
34template int X0<int>::f0(int);
35template int* X0<int>::f0(int*, int*);
36template int X0<int>::f0(int, float);
37
38template int X0<int>::f0(int) const; // expected-error{{does not refer}}
39template int* X0<int>::f0(int*, float*); // expected-error{{does not refer}}
40
41struct X1 { };
42typedef int X1::*MemPtr;
43
44template MemPtr X0<MemPtr>::f0(MemPtr); // expected-note{{requested here}}
45
46struct X2 {
47 int f0(int); // expected-note{{refers here}}
48
Douglas Gregor558c0322009-10-14 23:41:34 +000049 template<typename T> T f1(T) { return T(); }
50 template<typename T> T* f1(T*) { return 0; }
Douglas Gregord5a423b2009-09-25 18:43:00 +000051
Douglas Gregor558c0322009-10-14 23:41:34 +000052 template<typename T, typename U> void f2(T, U*) { } // expected-note{{candidate}}
53 template<typename T, typename U> void f2(T*, U) { } // expected-note{{candidate}}
Douglas Gregord5a423b2009-09-25 18:43:00 +000054};
55
56template int X2::f0(int); // expected-error{{not an instantiation}}
57
58template int *X2::f1(int *); // okay
59
60template void X2::f2(int *, int *); // expected-error{{ambiguous}}
Douglas Gregordb422df2009-09-25 21:45:23 +000061
62
Douglas Gregor558c0322009-10-14 23:41:34 +000063template<typename T> void print_type() { }
Douglas Gregordb422df2009-09-25 21:45:23 +000064
65template void print_type<int>();
66template void print_type<float>();
67
Douglas Gregor558c0322009-10-14 23:41:34 +000068template<typename T> void print_type(T*) { }
Douglas Gregordb422df2009-09-25 21:45:23 +000069
70template void print_type(int*);
71template void print_type<int>(float*); // expected-error{{does not refer}}
72
73void print_type(double*);
74template void print_type<double>(double*);
Douglas Gregorb2f81cf2009-10-01 23:51:25 +000075
76// PR5069
77template<int I> void foo0 (int (&)[I + 1]) { }
78template void foo0<2> (int (&)[3]);