1 // RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify -fenable-matrix %s
3 template <typename T
> // expected-note{{declared here}}
4 void matrix_template_1() {
5 using matrix1_t
= float __attribute__((matrix_type(T
, T
))); // expected-error{{'T' does not refer to a value}}
8 template <class C
> // expected-note{{declared here}}
9 void matrix_template_2() {
10 using matrix1_t
= float __attribute__((matrix_type(C
, C
))); // expected-error{{'C' does not refer to a value}}
13 template <unsigned Rows
, unsigned Cols
>
14 void matrix_template_3() {
15 using matrix1_t
= float __attribute__((matrix_type(Rows
, Cols
))); // expected-error{{zero matrix size}}
18 void instantiate_template_3() {
19 matrix_template_3
<1, 10>();
20 matrix_template_3
<0, 10>(); // expected-note{{in instantiation of function template specialization 'matrix_template_3<0U, 10U>' requested here}}
23 template <int Rows
, unsigned Cols
>
24 void matrix_template_4() {
25 using matrix1_t
= float __attribute__((matrix_type(Rows
, Cols
))); // expected-error{{matrix row size too large}}
28 void instantiate_template_4() {
29 matrix_template_4
<2, 10>();
30 matrix_template_4
<-3, 10>(); // expected-note{{in instantiation of function template specialization 'matrix_template_4<-3, 10U>' requested here}}
33 template <class T
, unsigned long R
, unsigned long C
>
34 using matrix
= T
__attribute__((matrix_type(R
, C
)));
36 template <class T
, unsigned long R
>
37 void use_matrix(matrix
<T
, R
, 10> &m
) {}
38 // expected-note@-1 {{candidate function [with T = float, R = 10]}}
40 template <class T
, unsigned long C
>
41 void use_matrix(matrix
<T
, 10, C
> &m
) {}
42 // expected-note@-1 {{candidate function [with T = float, C = 10]}}
44 void test_ambigous_deduction1() {
45 matrix
<float, 10, 10> m
;
47 // expected-error@-1 {{call to 'use_matrix' is ambiguous}}
50 template <class T
, long R
>
51 void type_conflict(matrix
<T
, R
, 10> &m
, T x
) {}
52 // expected-note@-1 {{candidate template ignored: deduced conflicting types for parameter 'T' ('float' vs. 'char *')}}
54 void test_type_conflict(char *p
) {
55 matrix
<float, 10, 10> m
;
57 // expected-error@-1 {{no matching function for call to 'type_conflict'}}
60 template <unsigned long R
, unsigned long C
>
61 matrix
<float, R
+ 1, C
+ 2> use_matrix_2(matrix
<int, R
, C
> &m
) {}
62 // expected-note@-1 {{candidate function template not viable: requires single argument 'm', but 2 arguments were provided}}
63 // expected-note@-2 {{candidate function template not viable: requires single argument 'm', but 2 arguments were provided}}
65 template <unsigned long R
, unsigned long C
>
66 void use_matrix_2(matrix
<int, R
+ 2, C
/ 2> &m1
, matrix
<float, R
, C
> &m2
) {}
67 // expected-note@-1 {{candidate function [with R = 3, C = 11] not viable: no known conversion from 'matrix<int, 5, 6>' (aka 'int __attribute__((matrix_type(5, 6)))') to 'matrix<int, 3UL + 2, 11UL / 2> &' (aka 'int __attribute__((matrix_type(5, 5)))&') for 1st argument}}
68 // expected-note@-2 {{candidate template ignored: deduced type 'matrix<float, 3UL, 4UL>' of 2nd parameter does not match adjusted type 'matrix<int, 3, 4>' of argument [with R = 3, C = 4]}}
70 template <typename T
, unsigned long R
, unsigned long C
>
71 void use_matrix_2(matrix
<T
, R
+ C
, C
> &m1
, matrix
<T
, R
, C
- R
> &m2
) {}
72 // expected-note@-1 {{candidate template ignored: deduced conflicting types for parameter 'T' ('int' vs. 'float')}}
73 // expected-note@-2 {{candidate template ignored: deduced type 'matrix<[...], 3UL + 4UL, 4UL>' of 1st parameter does not match adjusted type 'matrix<[...], 3, 4>' of argument [with T = int, R = 3, C = 4]}}
75 template <typename T
, unsigned long R
>
76 void use_matrix_3(matrix
<T
, R
- 2, R
> &m
) {}
77 // expected-note@-1 {{candidate template ignored: deduced type 'matrix<[...], 5UL - 2, 5UL>' of 1st parameter does not match adjusted type 'matrix<[...], 5, 5>' of argument [with T = unsigned int, R = 5]}}
79 void test_use_matrix_2() {
81 matrix
<float, 5, 8> r1
= use_matrix_2(m1
);
82 // expected-error@-1 {{cannot initialize a variable of type 'matrix<[...], 5, 8>' with an rvalue of type 'matrix<[...], 5UL + 1, 6UL + 2>'}}
85 matrix
<float, 5, 8> r2
= use_matrix_2(m2
);
86 // expected-error@-1 {{cannot initialize a variable of type 'matrix<[...], 5, 8>' with an rvalue of type 'matrix<[...], 4UL + 1, 5UL + 2>'}}
88 matrix
<float, 3, 11> m3
;
90 // expected-error@-1 {{no matching function for call to 'use_matrix_2'}}
94 // expected-error@-1 {{no matching function for call to 'use_matrix_2'}}
96 matrix
<unsigned, 5, 5> m5
;
98 // expected-error@-1 {{no matching function for call to 'use_matrix_3'}}
100 template <typename T
, unsigned R
, unsigned C
>
102 typedef T
__attribute__((matrix_type(R
, C
))) type
;
106 make1
<int, 5, 4>::type x
;
109 template <typename T
, unsigned R
, unsigned C
>
111 typedef T
__attribute__((matrix_type(R
, C
))) type
; // expected-error{{zero matrix size}}
115 make2
<int, 0, 1> x
; // expected-note{{in instantiation of}}
118 template <typename T
, unsigned R
, unsigned C
>
120 typedef T
__attribute__((matrix_type(R
, C
))) type
; // expected-error{{invalid matrix element type 's'}}
126 make3
<s
, 3, 3> x
; // expected-note{{in instantiation of}}
129 template <typename T
, T R
, unsigned C
>
131 typedef T
__attribute__((matrix_type(R
, C
))) type
;
135 make4
<int, 4, 5>::type x
;
138 typedef int *int_ptr
;
139 template <unsigned R
, unsigned C
>
141 typedef int_ptr
__attribute__((matrix_type(R
, C
))) type
; // expected-error{{invalid matrix element type}}
144 template <int R
, unsigned C
>
146 typedef int __attribute__((matrix_type(R
, C
))) type
;
155 namespace Deduction
{
156 template <typename T
>
159 template <typename T
, unsigned N
>
160 struct X0
<T
__attribute__((matrix_type(N
, 3)))> {
161 static const unsigned value
= 0;
164 template <typename T
>
165 struct X0
<T
__attribute__((matrix_type(4, 3)))> {
166 static const unsigned value
= 1;
169 template <unsigned N
>
170 struct X0
<float __attribute__((matrix_type(N
, 3)))> {
171 static const unsigned value
= 2;
175 struct X0
<float __attribute__((matrix_type(4, 3)))> {
176 static const unsigned value
= 3;
179 typedef int __attribute__((matrix_type(2, 3))) int2
;
180 typedef int __attribute__((matrix_type(4, 3))) int4
;
181 typedef float __attribute__((matrix_type(2, 3))) float2
;
182 typedef float __attribute__((matrix_type(4, 3))) float4
;
184 int array0
[X0
<int2
>::value
== 0 ? 1 : -1];
185 int array1
[X0
<int4
>::value
== 1 ? 1 : -1];
186 int array2
[X0
<float2
>::value
== 2 ? 1 : -1];
187 int array3
[X0
<float4
>::value
== 3 ? 1 : -1];
188 } // namespace Deduction