1a5728872c7702ddd09537c95bc3cbd20e1f2fb09Daniel Dunbar// RUN: %clang_cc1 -fsyntax-only -verify %s
2d5a423b279e787e9fdd8309fe52cb515388c54eaDouglas Gregor
3d5a423b279e787e9fdd8309fe52cb515388c54eaDouglas Gregortemplate void *; // expected-error{{expected unqualified-id}}
4d5a423b279e787e9fdd8309fe52cb515388c54eaDouglas Gregor
5d5a423b279e787e9fdd8309fe52cb515388c54eaDouglas Gregortemplate typedef void f0; // expected-error{{explicit instantiation of typedef}}
6d5a423b279e787e9fdd8309fe52cb515388c54eaDouglas Gregor
7d5a423b279e787e9fdd8309fe52cb515388c54eaDouglas Gregorint v0; // expected-note{{refers here}}
8d5a423b279e787e9fdd8309fe52cb515388c54eaDouglas Gregortemplate int v0; // expected-error{{does not refer}}
9d5a423b279e787e9fdd8309fe52cb515388c54eaDouglas Gregor
10d5a423b279e787e9fdd8309fe52cb515388c54eaDouglas Gregortemplate<typename T>
11d5a423b279e787e9fdd8309fe52cb515388c54eaDouglas Gregorstruct X0 {
12d5a423b279e787e9fdd8309fe52cb515388c54eaDouglas Gregor  static T value;
13d5a423b279e787e9fdd8309fe52cb515388c54eaDouglas Gregor
14d5a423b279e787e9fdd8309fe52cb515388c54eaDouglas Gregor  T f0(T x) {
15d5a423b279e787e9fdd8309fe52cb515388c54eaDouglas Gregor    return x + 1;  // expected-error{{invalid operands}}
16d5a423b279e787e9fdd8309fe52cb515388c54eaDouglas Gregor  }
17558c03222c77873a934b002073667a3c971fe8a9Douglas Gregor  T* f0(T*, T*) { return T(); }
18d5a423b279e787e9fdd8309fe52cb515388c54eaDouglas Gregor
19d5a423b279e787e9fdd8309fe52cb515388c54eaDouglas Gregor  template<typename U>
20558c03222c77873a934b002073667a3c971fe8a9Douglas Gregor  T f0(T, U) { return T(); }
21d5a423b279e787e9fdd8309fe52cb515388c54eaDouglas Gregor};
22d5a423b279e787e9fdd8309fe52cb515388c54eaDouglas Gregor
23558c03222c77873a934b002073667a3c971fe8a9Douglas Gregortemplate<typename T>
24558c03222c77873a934b002073667a3c971fe8a9Douglas GregorT X0<T>::value; // expected-error{{no matching constructor}}
25558c03222c77873a934b002073667a3c971fe8a9Douglas Gregor
26d5a423b279e787e9fdd8309fe52cb515388c54eaDouglas Gregortemplate int X0<int>::value;
27d5a423b279e787e9fdd8309fe52cb515388c54eaDouglas Gregor
28220ccbf2c9ef97034cce80561f9f46c4f1f63bc7John McCallstruct NotDefaultConstructible { // expected-note{{candidate constructor (the implicit copy constructor)}}
29b1622a1fd7b7f4ab8d00d0183d17c90ad25c14e3John McCall  NotDefaultConstructible(int); // expected-note{{candidate constructor}}
30d5a423b279e787e9fdd8309fe52cb515388c54eaDouglas Gregor};
31d5a423b279e787e9fdd8309fe52cb515388c54eaDouglas Gregor
32558c03222c77873a934b002073667a3c971fe8a9Douglas Gregortemplate NotDefaultConstructible X0<NotDefaultConstructible>::value; // expected-note{{instantiation}}
33d5a423b279e787e9fdd8309fe52cb515388c54eaDouglas Gregor
34d5a423b279e787e9fdd8309fe52cb515388c54eaDouglas Gregortemplate int X0<int>::f0(int);
35d5a423b279e787e9fdd8309fe52cb515388c54eaDouglas Gregortemplate int* X0<int>::f0(int*, int*);
36d5a423b279e787e9fdd8309fe52cb515388c54eaDouglas Gregortemplate int X0<int>::f0(int, float);
37d5a423b279e787e9fdd8309fe52cb515388c54eaDouglas Gregor
38d5a423b279e787e9fdd8309fe52cb515388c54eaDouglas Gregortemplate int X0<int>::f0(int) const; // expected-error{{does not refer}}
39d5a423b279e787e9fdd8309fe52cb515388c54eaDouglas Gregortemplate int* X0<int>::f0(int*, float*); // expected-error{{does not refer}}
40d5a423b279e787e9fdd8309fe52cb515388c54eaDouglas Gregor
41d5a423b279e787e9fdd8309fe52cb515388c54eaDouglas Gregorstruct X1 { };
42d5a423b279e787e9fdd8309fe52cb515388c54eaDouglas Gregortypedef int X1::*MemPtr;
43d5a423b279e787e9fdd8309fe52cb515388c54eaDouglas Gregor
44d5a423b279e787e9fdd8309fe52cb515388c54eaDouglas Gregortemplate MemPtr X0<MemPtr>::f0(MemPtr); // expected-note{{requested here}}
45d5a423b279e787e9fdd8309fe52cb515388c54eaDouglas Gregor
46d5a423b279e787e9fdd8309fe52cb515388c54eaDouglas Gregorstruct X2 {
47d5a423b279e787e9fdd8309fe52cb515388c54eaDouglas Gregor  int f0(int); // expected-note{{refers here}}
48d5a423b279e787e9fdd8309fe52cb515388c54eaDouglas Gregor
49558c03222c77873a934b002073667a3c971fe8a9Douglas Gregor  template<typename T> T f1(T) { return T(); }
50558c03222c77873a934b002073667a3c971fe8a9Douglas Gregor  template<typename T> T* f1(T*) { return 0; }
51d5a423b279e787e9fdd8309fe52cb515388c54eaDouglas Gregor
52558c03222c77873a934b002073667a3c971fe8a9Douglas Gregor  template<typename T, typename U> void f2(T, U*) { } // expected-note{{candidate}}
53558c03222c77873a934b002073667a3c971fe8a9Douglas Gregor  template<typename T, typename U> void f2(T*, U) { } // expected-note{{candidate}}
54d5a423b279e787e9fdd8309fe52cb515388c54eaDouglas Gregor};
55d5a423b279e787e9fdd8309fe52cb515388c54eaDouglas Gregor
56d5a423b279e787e9fdd8309fe52cb515388c54eaDouglas Gregortemplate int X2::f0(int); // expected-error{{not an instantiation}}
57d5a423b279e787e9fdd8309fe52cb515388c54eaDouglas Gregor
58d5a423b279e787e9fdd8309fe52cb515388c54eaDouglas Gregortemplate int *X2::f1(int *); // okay
59d5a423b279e787e9fdd8309fe52cb515388c54eaDouglas Gregor
60d5a423b279e787e9fdd8309fe52cb515388c54eaDouglas Gregortemplate void X2::f2(int *, int *); // expected-error{{ambiguous}}
61db422dffb720ff41d0b60e228f45c685600ffa9eDouglas Gregor
62db422dffb720ff41d0b60e228f45c685600ffa9eDouglas Gregor
63558c03222c77873a934b002073667a3c971fe8a9Douglas Gregortemplate<typename T> void print_type() { }
64db422dffb720ff41d0b60e228f45c685600ffa9eDouglas Gregor
65db422dffb720ff41d0b60e228f45c685600ffa9eDouglas Gregortemplate void print_type<int>();
66db422dffb720ff41d0b60e228f45c685600ffa9eDouglas Gregortemplate void print_type<float>();
67db422dffb720ff41d0b60e228f45c685600ffa9eDouglas Gregor
68558c03222c77873a934b002073667a3c971fe8a9Douglas Gregortemplate<typename T> void print_type(T*) { }
69db422dffb720ff41d0b60e228f45c685600ffa9eDouglas Gregor
70db422dffb720ff41d0b60e228f45c685600ffa9eDouglas Gregortemplate void print_type(int*);
71db422dffb720ff41d0b60e228f45c685600ffa9eDouglas Gregortemplate void print_type<int>(float*); // expected-error{{does not refer}}
72db422dffb720ff41d0b60e228f45c685600ffa9eDouglas Gregor
73db422dffb720ff41d0b60e228f45c685600ffa9eDouglas Gregorvoid print_type(double*);
74db422dffb720ff41d0b60e228f45c685600ffa9eDouglas Gregortemplate void print_type<double>(double*);
75b2f81cf7f8445e0c65c0428f4fbb0442566916b8Douglas Gregor
76b2f81cf7f8445e0c65c0428f4fbb0442566916b8Douglas Gregor// PR5069
77b2f81cf7f8445e0c65c0428f4fbb0442566916b8Douglas Gregortemplate<int I> void foo0 (int (&)[I + 1]) { }
78b2f81cf7f8445e0c65c0428f4fbb0442566916b8Douglas Gregortemplate void foo0<2> (int (&)[3]);
79291b441a095b289c30d9f311fe37a2cf5ed6fd45Chandler Carruth
80291b441a095b289c30d9f311fe37a2cf5ed6fd45Chandler Carruthnamespace explicit_instantiation_after_implicit_instantiation {
81291b441a095b289c30d9f311fe37a2cf5ed6fd45Chandler Carruth  template <int I> struct X0 { static int x; };
82291b441a095b289c30d9f311fe37a2cf5ed6fd45Chandler Carruth  template <int I> int X0<I>::x;
83291b441a095b289c30d9f311fe37a2cf5ed6fd45Chandler Carruth  void test1() { (void)&X0<1>::x; }
84291b441a095b289c30d9f311fe37a2cf5ed6fd45Chandler Carruth  template struct X0<1>;
85291b441a095b289c30d9f311fe37a2cf5ed6fd45Chandler Carruth}
86669eed8d676458c701f45f7fd686f01de2dee53bDouglas Gregor
877306ebfacfa51ba5270fd20f162f62d2ed813485Douglas Gregortemplate<typename> struct X3 { };
887306ebfacfa51ba5270fd20f162f62d2ed813485Douglas Gregorinline template struct X3<int>; // expected-warning{{ignoring 'inline' keyword on explicit template instantiation}}
897306ebfacfa51ba5270fd20f162f62d2ed813485Douglas Gregorstatic template struct X3<float>; // expected-warning{{ignoring 'static' keyword on explicit template instantiation}}
907306ebfacfa51ba5270fd20f162f62d2ed813485Douglas Gregor
91d941fa4ff0d0d64b5a541dbd4f99693bff7f6e8dSebastian Redlnamespace PR7622 {
92669eed8d676458c701f45f7fd686f01de2dee53bDouglas Gregor  template<typename,typename=int>
93669eed8d676458c701f45f7fd686f01de2dee53bDouglas Gregor  struct basic_streambuf;
94669eed8d676458c701f45f7fd686f01de2dee53bDouglas Gregor
95669eed8d676458c701f45f7fd686f01de2dee53bDouglas Gregor  template<typename,typename>
96669eed8d676458c701f45f7fd686f01de2dee53bDouglas Gregor  struct basic_streambuf{friend bob<>()}; // expected-error{{unknown type name 'bob'}} \
97669eed8d676458c701f45f7fd686f01de2dee53bDouglas Gregor  // expected-error{{ expected member name or ';' after declaration specifiers}}
98d941fa4ff0d0d64b5a541dbd4f99693bff7f6e8dSebastian Redl  template struct basic_streambuf<int>;
99d941fa4ff0d0d64b5a541dbd4f99693bff7f6e8dSebastian Redl}
100