Daniel Dunbar | a572887 | 2009-12-15 20:14:24 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -fsyntax-only -verify %s |
Douglas Gregor | b9aa6b2 | 2009-09-24 23:14:47 +0000 | [diff] [blame] | 2 | |
| 3 | template<int N> void f0(int (&array)[N]); |
| 4 | |
| 5 | // Simple function template specialization (using overloading) |
| 6 | template<> void f0(int (&array)[1]); |
| 7 | |
| 8 | void test_f0() { |
| 9 | int iarr1[1]; |
| 10 | f0(iarr1); |
| 11 | } |
| 12 | |
| 13 | // Function template specialization where there are no matches |
| 14 | template<> void f0(char (&array)[1]); // expected-error{{no function template matches}} |
Douglas Gregor | 0b60d9e | 2009-09-25 23:53:26 +0000 | [diff] [blame] | 15 | template<> void f0<2>(int (&array)[2]) { } |
Douglas Gregor | b9aa6b2 | 2009-09-24 23:14:47 +0000 | [diff] [blame] | 16 | |
| 17 | // Function template specialization that requires partial ordering |
| 18 | template<typename T, int N> void f1(T (&array)[N]); // expected-note{{matches}} |
| 19 | template<int N> void f1(int (&array)[N]); // expected-note{{matches}} |
| 20 | |
| 21 | template<> void f1(float (&array)[1]); |
| 22 | template<> void f1(int (&array)[1]); |
| 23 | |
| 24 | // Function template specialization that results in an ambiguity |
| 25 | template<typename T> void f1(T (&array)[17]); // expected-note{{matches}} |
| 26 | template<> void f1(int (&array)[17]); // expected-error{{ambiguous}} |
Douglas Gregor | 0b60d9e | 2009-09-25 23:53:26 +0000 | [diff] [blame] | 27 | |
| 28 | // Resolving that ambiguity with explicitly-specified template arguments. |
| 29 | template<int N> void f2(double (&array)[N]); |
| 30 | template<typename T> void f2(T (&array)[42]); |
| 31 | |
| 32 | template<> void f2<double>(double (&array)[42]); |
| 33 | template<> void f2<42>(double (&array)[42]); |
| 34 | |
| 35 | void f2<25>(double (&array)[25]); // expected-error{{specialization}} |
Douglas Gregor | 277d280 | 2010-01-11 22:40:45 +0000 | [diff] [blame] | 36 | |
| 37 | // PR5833 |
| 38 | namespace PR5833 { |
| 39 | template <typename T> bool f0(T &t1); |
| 40 | template <> bool f0<float>(float &t1); |
| 41 | } |
| 42 | template <> bool PR5833::f0<float>(float &t1) {} |
| 43 | |
Douglas Gregor | 5505c72 | 2011-01-24 18:54:39 +0000 | [diff] [blame] | 44 | // PR8295 |
| 45 | namespace PR8295 { |
| 46 | template <typename T> void f(T t) {} |
| 47 | template <typename T> void f<T*>(T* t) {} // expected-error{{function template partial specialization is not allowed}} |
| 48 | } |