18fbe78f6SDaniel Dunbar // RUN: %clang_cc1 -fsyntax-only -verify %s 23a923c2dSDouglas Gregor 398b20f12SLarisse Voufo template <int N> 498b20f12SLarisse Voufo void f0(int (&array)[N]); // expected-note {{candidate template ignored: could not match 'int' against 'char'}} 53a923c2dSDouglas Gregor 63a923c2dSDouglas Gregor // Simple function template specialization (using overloading) 73a923c2dSDouglas Gregor template<> void f0(int (&array)[1]); 83a923c2dSDouglas Gregor test_f0()93a923c2dSDouglas Gregorvoid test_f0() { 103a923c2dSDouglas Gregor int iarr1[1]; 113a923c2dSDouglas Gregor f0(iarr1); 123a923c2dSDouglas Gregor } 133a923c2dSDouglas Gregor 143a923c2dSDouglas Gregor // Function template specialization where there are no matches 153a923c2dSDouglas Gregor template<> void f0(char (&array)[1]); // expected-error{{no function template matches}} f0(int (& array)[2])160e876e01SDouglas Gregortemplate<> void f0<2>(int (&array)[2]) { } 173a923c2dSDouglas Gregor 183a923c2dSDouglas Gregor // Function template specialization that requires partial ordering 193a923c2dSDouglas Gregor template<typename T, int N> void f1(T (&array)[N]); // expected-note{{matches}} 203a923c2dSDouglas Gregor template<int N> void f1(int (&array)[N]); // expected-note{{matches}} 213a923c2dSDouglas Gregor 223a923c2dSDouglas Gregor template<> void f1(float (&array)[1]); 233a923c2dSDouglas Gregor template<> void f1(int (&array)[1]); 243a923c2dSDouglas Gregor 253a923c2dSDouglas Gregor // Function template specialization that results in an ambiguity 263a923c2dSDouglas Gregor template<typename T> void f1(T (&array)[17]); // expected-note{{matches}} 273a923c2dSDouglas Gregor template<> void f1(int (&array)[17]); // expected-error{{ambiguous}} 280e876e01SDouglas Gregor 290e876e01SDouglas Gregor // Resolving that ambiguity with explicitly-specified template arguments. 300e876e01SDouglas Gregor template<int N> void f2(double (&array)[N]); 310e876e01SDouglas Gregor template<typename T> void f2(T (&array)[42]); 320e876e01SDouglas Gregor 330e876e01SDouglas Gregor template<> void f2<double>(double (&array)[42]); 340e876e01SDouglas Gregor template<> void f2<42>(double (&array)[42]); 350e876e01SDouglas Gregor 360e876e01SDouglas Gregor void f2<25>(double (&array)[25]); // expected-error{{specialization}} 3788f3eb89SDouglas Gregor 3888f3eb89SDouglas Gregor // PR5833 3988f3eb89SDouglas Gregor namespace PR5833 { 4088f3eb89SDouglas Gregor template <typename T> bool f0(T &t1); 4188f3eb89SDouglas Gregor template <> bool f0<float>(float &t1); 4288f3eb89SDouglas Gregor } f0(float & t1)4388f3eb89SDouglas Gregortemplate <> bool PR5833::f0<float>(float &t1) {} 4488f3eb89SDouglas Gregor 45a5f6f9c7SDouglas Gregor // PR8295 46a5f6f9c7SDouglas Gregor namespace PR8295 { f(T t)47a5f6f9c7SDouglas Gregor template <typename T> void f(T t) {} f(T * t)48a5f6f9c7SDouglas Gregor template <typename T> void f<T*>(T* t) {} // expected-error{{function template partial specialization is not allowed}} 49a5f6f9c7SDouglas Gregor } 50b48e62fbSRichard Trieu 51b48e62fbSRichard Trieu class Foo { 52b48e62fbSRichard Trieu template<class T> 53b48e62fbSRichard Trieu static void Bar(const T& input); 54b48e62fbSRichard Trieu 55b48e62fbSRichard Trieu // Don't crash here. 56b48e62fbSRichard Trieu template<> Bar(const long & input)57*c660c8f5SRichard Smith static void Bar(const long& input) {} // expected-warning{{explicit specialization cannot have a storage class}} 58b48e62fbSRichard Trieu }; 59