blob: a0d41b2053443faa113254acee32387d1f232821 [file] [log] [blame]
Daniel Dunbara5728872009-12-15 20:14:24 +00001// RUN: %clang_cc1 -fsyntax-only -verify %s
Douglas Gregorb9aa6b22009-09-24 23:14:47 +00002
3template<int N> void f0(int (&array)[N]);
4
5// Simple function template specialization (using overloading)
6template<> void f0(int (&array)[1]);
7
8void test_f0() {
9 int iarr1[1];
10 f0(iarr1);
11}
12
13// Function template specialization where there are no matches
14template<> void f0(char (&array)[1]); // expected-error{{no function template matches}}
Douglas Gregor0b60d9e2009-09-25 23:53:26 +000015template<> void f0<2>(int (&array)[2]) { }
Douglas Gregorb9aa6b22009-09-24 23:14:47 +000016
17// Function template specialization that requires partial ordering
18template<typename T, int N> void f1(T (&array)[N]); // expected-note{{matches}}
19template<int N> void f1(int (&array)[N]); // expected-note{{matches}}
20
21template<> void f1(float (&array)[1]);
22template<> void f1(int (&array)[1]);
23
24// Function template specialization that results in an ambiguity
25template<typename T> void f1(T (&array)[17]); // expected-note{{matches}}
26template<> void f1(int (&array)[17]); // expected-error{{ambiguous}}
Douglas Gregor0b60d9e2009-09-25 23:53:26 +000027
28// Resolving that ambiguity with explicitly-specified template arguments.
29template<int N> void f2(double (&array)[N]);
30template<typename T> void f2(T (&array)[42]);
31
32template<> void f2<double>(double (&array)[42]);
33template<> void f2<42>(double (&array)[42]);
34
35void f2<25>(double (&array)[25]); // expected-error{{specialization}}
Douglas Gregor277d2802010-01-11 22:40:45 +000036
37// PR5833
38namespace PR5833 {
39 template <typename T> bool f0(T &t1);
40 template <> bool f0<float>(float &t1);
41}
42template <> bool PR5833::f0<float>(float &t1) {}
43
Douglas Gregor5505c722011-01-24 18:54:39 +000044// PR8295
45namespace 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}