Daniel Dunbar | 8fbe78f | 2009-12-15 20:14:24 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -fsyntax-only -verify %s |
Douglas Gregor | 3a923c2d | 2009-09-24 23:14:47 +0000 | [diff] [blame] | 2 | |
Larisse Voufo | 98b20f1 | 2013-07-19 23:00:19 +0000 | [diff] [blame] | 3 | template <int N> |
| 4 | void f0(int (&array)[N]); // expected-note {{candidate template ignored: could not match 'int' against 'char'}} |
Douglas Gregor | 3a923c2d | 2009-09-24 23:14:47 +0000 | [diff] [blame] | 5 | |
| 6 | // Simple function template specialization (using overloading) |
| 7 | template<> void f0(int (&array)[1]); |
| 8 | |
| 9 | void test_f0() { |
| 10 | int iarr1[1]; |
| 11 | f0(iarr1); |
| 12 | } |
| 13 | |
| 14 | // Function template specialization where there are no matches |
| 15 | template<> void f0(char (&array)[1]); // expected-error{{no function template matches}} |
Douglas Gregor | 0e876e0 | 2009-09-25 23:53:26 +0000 | [diff] [blame] | 16 | template<> void f0<2>(int (&array)[2]) { } |
Douglas Gregor | 3a923c2d | 2009-09-24 23:14:47 +0000 | [diff] [blame] | 17 | |
| 18 | // Function template specialization that requires partial ordering |
| 19 | template<typename T, int N> void f1(T (&array)[N]); // expected-note{{matches}} |
| 20 | template<int N> void f1(int (&array)[N]); // expected-note{{matches}} |
| 21 | |
| 22 | template<> void f1(float (&array)[1]); |
| 23 | template<> void f1(int (&array)[1]); |
| 24 | |
| 25 | // Function template specialization that results in an ambiguity |
| 26 | template<typename T> void f1(T (&array)[17]); // expected-note{{matches}} |
| 27 | template<> void f1(int (&array)[17]); // expected-error{{ambiguous}} |
Douglas Gregor | 0e876e0 | 2009-09-25 23:53:26 +0000 | [diff] [blame] | 28 | |
| 29 | // Resolving that ambiguity with explicitly-specified template arguments. |
| 30 | template<int N> void f2(double (&array)[N]); |
| 31 | template<typename T> void f2(T (&array)[42]); |
| 32 | |
| 33 | template<> void f2<double>(double (&array)[42]); |
| 34 | template<> void f2<42>(double (&array)[42]); |
| 35 | |
| 36 | void f2<25>(double (&array)[25]); // expected-error{{specialization}} |
Douglas Gregor | 88f3eb8 | 2010-01-11 22:40:45 +0000 | [diff] [blame] | 37 | |
| 38 | // PR5833 |
| 39 | namespace PR5833 { |
| 40 | template <typename T> bool f0(T &t1); |
| 41 | template <> bool f0<float>(float &t1); |
| 42 | } |
| 43 | template <> bool PR5833::f0<float>(float &t1) {} |
| 44 | |
Douglas Gregor | a5f6f9c | 2011-01-24 18:54:39 +0000 | [diff] [blame] | 45 | // PR8295 |
| 46 | namespace PR8295 { |
| 47 | template <typename T> void f(T t) {} |
| 48 | template <typename T> void f<T*>(T* t) {} // expected-error{{function template partial specialization is not allowed}} |
| 49 | } |
Richard Trieu | b48e62f | 2013-05-16 02:14:08 +0000 | [diff] [blame] | 50 | |
| 51 | class Foo { |
| 52 | template<class T> |
| 53 | static void Bar(const T& input); |
| 54 | |
| 55 | // Don't crash here. |
| 56 | template<> |
| 57 | static void Bar(const long& input) {} // expected-error{{explicit specialization of 'Bar' in class scope}} |
| 58 | }; |