2009-12-16 04:14:24 +08:00
|
|
|
// RUN: %clang_cc1 -fsyntax-only -verify %s
|
2009-09-25 07:14:47 +08:00
|
|
|
|
2013-07-20 07:00:19 +08:00
|
|
|
template <int N>
|
|
|
|
void f0(int (&array)[N]); // expected-note {{candidate template ignored: could not match 'int' against 'char'}}
|
2009-09-25 07:14:47 +08:00
|
|
|
|
|
|
|
// Simple function template specialization (using overloading)
|
|
|
|
template<> void f0(int (&array)[1]);
|
|
|
|
|
|
|
|
void test_f0() {
|
|
|
|
int iarr1[1];
|
|
|
|
f0(iarr1);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Function template specialization where there are no matches
|
|
|
|
template<> void f0(char (&array)[1]); // expected-error{{no function template matches}}
|
2009-09-26 07:53:26 +08:00
|
|
|
template<> void f0<2>(int (&array)[2]) { }
|
2009-09-25 07:14:47 +08:00
|
|
|
|
|
|
|
// Function template specialization that requires partial ordering
|
|
|
|
template<typename T, int N> void f1(T (&array)[N]); // expected-note{{matches}}
|
|
|
|
template<int N> void f1(int (&array)[N]); // expected-note{{matches}}
|
|
|
|
|
|
|
|
template<> void f1(float (&array)[1]);
|
|
|
|
template<> void f1(int (&array)[1]);
|
|
|
|
|
|
|
|
// Function template specialization that results in an ambiguity
|
|
|
|
template<typename T> void f1(T (&array)[17]); // expected-note{{matches}}
|
|
|
|
template<> void f1(int (&array)[17]); // expected-error{{ambiguous}}
|
2009-09-26 07:53:26 +08:00
|
|
|
|
|
|
|
// Resolving that ambiguity with explicitly-specified template arguments.
|
|
|
|
template<int N> void f2(double (&array)[N]);
|
|
|
|
template<typename T> void f2(T (&array)[42]);
|
|
|
|
|
|
|
|
template<> void f2<double>(double (&array)[42]);
|
|
|
|
template<> void f2<42>(double (&array)[42]);
|
|
|
|
|
|
|
|
void f2<25>(double (&array)[25]); // expected-error{{specialization}}
|
2010-01-12 06:40:45 +08:00
|
|
|
|
|
|
|
// PR5833
|
|
|
|
namespace PR5833 {
|
|
|
|
template <typename T> bool f0(T &t1);
|
|
|
|
template <> bool f0<float>(float &t1);
|
|
|
|
}
|
|
|
|
template <> bool PR5833::f0<float>(float &t1) {}
|
|
|
|
|
2011-01-25 02:54:39 +08:00
|
|
|
// PR8295
|
|
|
|
namespace PR8295 {
|
|
|
|
template <typename T> void f(T t) {}
|
|
|
|
template <typename T> void f<T*>(T* t) {} // expected-error{{function template partial specialization is not allowed}}
|
|
|
|
}
|
2013-05-16 10:14:08 +08:00
|
|
|
|
|
|
|
class Foo {
|
|
|
|
template<class T>
|
|
|
|
static void Bar(const T& input);
|
|
|
|
|
|
|
|
// Don't crash here.
|
|
|
|
template<>
|
|
|
|
static void Bar(const long& input) {} // expected-error{{explicit specialization of 'Bar' in class scope}}
|
|
|
|
};
|