annotate clang/test/SemaTemplate/function-template-specialization.cpp @ 150:1d019706d866

LLVM10
author anatofuz
date Thu, 13 Feb 2020 15:10:13 +0900
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
150
anatofuz
parents:
diff changeset
1 // RUN: %clang_cc1 -fsyntax-only -verify %s
anatofuz
parents:
diff changeset
2
anatofuz
parents:
diff changeset
3 template <int N>
anatofuz
parents:
diff changeset
4 void f0(int (&array)[N]); // expected-note {{candidate template ignored: could not match 'int' against 'char'}}
anatofuz
parents:
diff changeset
5
anatofuz
parents:
diff changeset
6 // Simple function template specialization (using overloading)
anatofuz
parents:
diff changeset
7 template<> void f0(int (&array)[1]);
anatofuz
parents:
diff changeset
8
anatofuz
parents:
diff changeset
9 void test_f0() {
anatofuz
parents:
diff changeset
10 int iarr1[1];
anatofuz
parents:
diff changeset
11 f0(iarr1);
anatofuz
parents:
diff changeset
12 }
anatofuz
parents:
diff changeset
13
anatofuz
parents:
diff changeset
14 // Function template specialization where there are no matches
anatofuz
parents:
diff changeset
15 template<> void f0(char (&array)[1]); // expected-error{{no function template matches}}
anatofuz
parents:
diff changeset
16 template<> void f0<2>(int (&array)[2]) { }
anatofuz
parents:
diff changeset
17
anatofuz
parents:
diff changeset
18 // Function template specialization that requires partial ordering
anatofuz
parents:
diff changeset
19 template<typename T, int N> void f1(T (&array)[N]); // expected-note{{matches}}
anatofuz
parents:
diff changeset
20 template<int N> void f1(int (&array)[N]); // expected-note{{matches}}
anatofuz
parents:
diff changeset
21
anatofuz
parents:
diff changeset
22 template<> void f1(float (&array)[1]);
anatofuz
parents:
diff changeset
23 template<> void f1(int (&array)[1]);
anatofuz
parents:
diff changeset
24
anatofuz
parents:
diff changeset
25 // Function template specialization that results in an ambiguity
anatofuz
parents:
diff changeset
26 template<typename T> void f1(T (&array)[17]); // expected-note{{matches}}
anatofuz
parents:
diff changeset
27 template<> void f1(int (&array)[17]); // expected-error{{ambiguous}}
anatofuz
parents:
diff changeset
28
anatofuz
parents:
diff changeset
29 // Resolving that ambiguity with explicitly-specified template arguments.
anatofuz
parents:
diff changeset
30 template<int N> void f2(double (&array)[N]);
anatofuz
parents:
diff changeset
31 template<typename T> void f2(T (&array)[42]);
anatofuz
parents:
diff changeset
32
anatofuz
parents:
diff changeset
33 template<> void f2<double>(double (&array)[42]);
anatofuz
parents:
diff changeset
34 template<> void f2<42>(double (&array)[42]);
anatofuz
parents:
diff changeset
35
anatofuz
parents:
diff changeset
36 void f2<25>(double (&array)[25]); // expected-error{{specialization}}
anatofuz
parents:
diff changeset
37
anatofuz
parents:
diff changeset
38 // PR5833
anatofuz
parents:
diff changeset
39 namespace PR5833 {
anatofuz
parents:
diff changeset
40 template <typename T> bool f0(T &t1);
anatofuz
parents:
diff changeset
41 template <> bool f0<float>(float &t1);
anatofuz
parents:
diff changeset
42 }
anatofuz
parents:
diff changeset
43 template <> bool PR5833::f0<float>(float &t1) {}
anatofuz
parents:
diff changeset
44
anatofuz
parents:
diff changeset
45 // PR8295
anatofuz
parents:
diff changeset
46 namespace PR8295 {
anatofuz
parents:
diff changeset
47 template <typename T> void f(T t) {}
anatofuz
parents:
diff changeset
48 template <typename T> void f<T*>(T* t) {} // expected-error{{function template partial specialization is not allowed}}
anatofuz
parents:
diff changeset
49 }
anatofuz
parents:
diff changeset
50
anatofuz
parents:
diff changeset
51 class Foo {
anatofuz
parents:
diff changeset
52 template<class T>
anatofuz
parents:
diff changeset
53 static void Bar(const T& input);
anatofuz
parents:
diff changeset
54
anatofuz
parents:
diff changeset
55 // Don't crash here.
anatofuz
parents:
diff changeset
56 template<>
anatofuz
parents:
diff changeset
57 static void Bar(const long& input) {} // expected-warning{{explicit specialization cannot have a storage class}}
anatofuz
parents:
diff changeset
58 };