1ffcaed32SFlorian Hahn // RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify -fenable-matrix %s
2ffcaed32SFlorian Hahn
3ffcaed32SFlorian Hahn template <typename T> // expected-note{{declared here}}
matrix_template_1()4ffcaed32SFlorian Hahn void matrix_template_1() {
5ffcaed32SFlorian Hahn using matrix1_t = float __attribute__((matrix_type(T, T))); // expected-error{{'T' does not refer to a value}}
6ffcaed32SFlorian Hahn }
7ffcaed32SFlorian Hahn
8ffcaed32SFlorian Hahn template <class C> // expected-note{{declared here}}
matrix_template_2()9ffcaed32SFlorian Hahn void matrix_template_2() {
10ffcaed32SFlorian Hahn using matrix1_t = float __attribute__((matrix_type(C, C))); // expected-error{{'C' does not refer to a value}}
11ffcaed32SFlorian Hahn }
12ffcaed32SFlorian Hahn
13ffcaed32SFlorian Hahn template <unsigned Rows, unsigned Cols>
matrix_template_3()14ffcaed32SFlorian Hahn void matrix_template_3() {
15ffcaed32SFlorian Hahn using matrix1_t = float __attribute__((matrix_type(Rows, Cols))); // expected-error{{zero matrix size}}
16ffcaed32SFlorian Hahn }
17ffcaed32SFlorian Hahn
instantiate_template_3()18ffcaed32SFlorian Hahn void instantiate_template_3() {
19ffcaed32SFlorian Hahn matrix_template_3<1, 10>();
20*99d63ccfSPratyush Das matrix_template_3<0, 10>(); // expected-note{{in instantiation of function template specialization 'matrix_template_3<0U, 10U>' requested here}}
21ffcaed32SFlorian Hahn }
22ffcaed32SFlorian Hahn
23ffcaed32SFlorian Hahn template <int Rows, unsigned Cols>
matrix_template_4()24ffcaed32SFlorian Hahn void matrix_template_4() {
25ffcaed32SFlorian Hahn using matrix1_t = float __attribute__((matrix_type(Rows, Cols))); // expected-error{{matrix row size too large}}
26ffcaed32SFlorian Hahn }
27ffcaed32SFlorian Hahn
instantiate_template_4()28ffcaed32SFlorian Hahn void instantiate_template_4() {
29ffcaed32SFlorian Hahn matrix_template_4<2, 10>();
30*99d63ccfSPratyush Das matrix_template_4<-3, 10>(); // expected-note{{in instantiation of function template specialization 'matrix_template_4<-3, 10U>' requested here}}
31ffcaed32SFlorian Hahn }
32ffcaed32SFlorian Hahn
33ffcaed32SFlorian Hahn template <class T, unsigned long R, unsigned long C>
34ffcaed32SFlorian Hahn using matrix = T __attribute__((matrix_type(R, C)));
35ffcaed32SFlorian Hahn
36ffcaed32SFlorian Hahn template <class T, unsigned long R>
use_matrix(matrix<T,R,10> & m)37ffcaed32SFlorian Hahn void use_matrix(matrix<T, R, 10> &m) {}
38ffcaed32SFlorian Hahn // expected-note@-1 {{candidate function [with T = float, R = 10]}}
39ffcaed32SFlorian Hahn
40ffcaed32SFlorian Hahn template <class T, unsigned long C>
use_matrix(matrix<T,10,C> & m)41ffcaed32SFlorian Hahn void use_matrix(matrix<T, 10, C> &m) {}
42ffcaed32SFlorian Hahn // expected-note@-1 {{candidate function [with T = float, C = 10]}}
43ffcaed32SFlorian Hahn
test_ambigous_deduction1()44ffcaed32SFlorian Hahn void test_ambigous_deduction1() {
45ffcaed32SFlorian Hahn matrix<float, 10, 10> m;
46ffcaed32SFlorian Hahn use_matrix(m);
47ffcaed32SFlorian Hahn // expected-error@-1 {{call to 'use_matrix' is ambiguous}}
48ffcaed32SFlorian Hahn }
49ffcaed32SFlorian Hahn
50ffcaed32SFlorian Hahn template <class T, long R>
type_conflict(matrix<T,R,10> & m,T x)51ffcaed32SFlorian Hahn void type_conflict(matrix<T, R, 10> &m, T x) {}
52ffcaed32SFlorian Hahn // expected-note@-1 {{candidate template ignored: deduced conflicting types for parameter 'T' ('float' vs. 'char *')}}
53ffcaed32SFlorian Hahn
test_type_conflict(char * p)54ffcaed32SFlorian Hahn void test_type_conflict(char *p) {
55ffcaed32SFlorian Hahn matrix<float, 10, 10> m;
56ffcaed32SFlorian Hahn type_conflict(m, p);
57ffcaed32SFlorian Hahn // expected-error@-1 {{no matching function for call to 'type_conflict'}}
58ffcaed32SFlorian Hahn }
59ffcaed32SFlorian Hahn
60ffcaed32SFlorian Hahn template <unsigned long R, unsigned long C>
use_matrix_2(matrix<int,R,C> & m)61ffcaed32SFlorian Hahn matrix<float, R + 1, C + 2> use_matrix_2(matrix<int, R, C> &m) {}
62ffcaed32SFlorian Hahn // expected-note@-1 {{candidate function template not viable: requires single argument 'm', but 2 arguments were provided}}
63ffcaed32SFlorian Hahn // expected-note@-2 {{candidate function template not viable: requires single argument 'm', but 2 arguments were provided}}
64ffcaed32SFlorian Hahn
65ffcaed32SFlorian Hahn template <unsigned long R, unsigned long C>
use_matrix_2(matrix<int,R+2,C/2> & m1,matrix<float,R,C> & m2)66ffcaed32SFlorian Hahn void use_matrix_2(matrix<int, R + 2, C / 2> &m1, matrix<float, R, C> &m2) {}
67ffcaed32SFlorian Hahn // 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}}
68ffcaed32SFlorian Hahn // 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]}}
69ffcaed32SFlorian Hahn
70ffcaed32SFlorian Hahn template <typename T, unsigned long R, unsigned long C>
use_matrix_2(matrix<T,R+C,C> & m1,matrix<T,R,C-R> & m2)71ffcaed32SFlorian Hahn void use_matrix_2(matrix<T, R + C, C> &m1, matrix<T, R, C - R> &m2) {}
72ffcaed32SFlorian Hahn // expected-note@-1 {{candidate template ignored: deduced conflicting types for parameter 'T' ('int' vs. 'float')}}
73ffcaed32SFlorian Hahn // 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]}}
74ffcaed32SFlorian Hahn
75ffcaed32SFlorian Hahn template <typename T, unsigned long R>
use_matrix_3(matrix<T,R-2,R> & m)76ffcaed32SFlorian Hahn void use_matrix_3(matrix<T, R - 2, R> &m) {}
77ffcaed32SFlorian Hahn // 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]}}
78ffcaed32SFlorian Hahn
test_use_matrix_2()79ffcaed32SFlorian Hahn void test_use_matrix_2() {
80ffcaed32SFlorian Hahn matrix<int, 5, 6> m1;
81ffcaed32SFlorian Hahn matrix<float, 5, 8> r1 = use_matrix_2(m1);
82ffcaed32SFlorian Hahn // expected-error@-1 {{cannot initialize a variable of type 'matrix<[...], 5, 8>' with an rvalue of type 'matrix<[...], 5UL + 1, 6UL + 2>'}}
83ffcaed32SFlorian Hahn
84ffcaed32SFlorian Hahn matrix<int, 4, 5> m2;
85ffcaed32SFlorian Hahn matrix<float, 5, 8> r2 = use_matrix_2(m2);
86ffcaed32SFlorian Hahn // expected-error@-1 {{cannot initialize a variable of type 'matrix<[...], 5, 8>' with an rvalue of type 'matrix<[...], 4UL + 1, 5UL + 2>'}}
87ffcaed32SFlorian Hahn
88ffcaed32SFlorian Hahn matrix<float, 3, 11> m3;
89ffcaed32SFlorian Hahn use_matrix_2(m1, m3);
90ffcaed32SFlorian Hahn // expected-error@-1 {{no matching function for call to 'use_matrix_2'}}
91ffcaed32SFlorian Hahn
92ffcaed32SFlorian Hahn matrix<int, 3, 4> m4;
93ffcaed32SFlorian Hahn use_matrix_2(m4, m4);
94ffcaed32SFlorian Hahn // expected-error@-1 {{no matching function for call to 'use_matrix_2'}}
95ffcaed32SFlorian Hahn
96ffcaed32SFlorian Hahn matrix<unsigned, 5, 5> m5;
97ffcaed32SFlorian Hahn use_matrix_3(m5);
98ffcaed32SFlorian Hahn // expected-error@-1 {{no matching function for call to 'use_matrix_3'}}
99ffcaed32SFlorian Hahn }
100ffcaed32SFlorian Hahn template <typename T, unsigned R, unsigned C>
101ffcaed32SFlorian Hahn struct make1 {
102ffcaed32SFlorian Hahn typedef T __attribute__((matrix_type(R, C))) type;
103ffcaed32SFlorian Hahn };
104ffcaed32SFlorian Hahn
test_make1()105ffcaed32SFlorian Hahn void test_make1() {
106ffcaed32SFlorian Hahn make1<int, 5, 4>::type x;
107ffcaed32SFlorian Hahn }
108ffcaed32SFlorian Hahn
109ffcaed32SFlorian Hahn template <typename T, unsigned R, unsigned C>
110ffcaed32SFlorian Hahn struct make2 {
111ffcaed32SFlorian Hahn typedef T __attribute__((matrix_type(R, C))) type; // expected-error{{zero matrix size}}
112ffcaed32SFlorian Hahn };
113ffcaed32SFlorian Hahn
test_make2()114ffcaed32SFlorian Hahn int test_make2() {
115ffcaed32SFlorian Hahn make2<int, 0, 1> x; // expected-note{{in instantiation of}}
116ffcaed32SFlorian Hahn }
117ffcaed32SFlorian Hahn
118ffcaed32SFlorian Hahn template <typename T, unsigned R, unsigned C>
119ffcaed32SFlorian Hahn struct make3 {
120ffcaed32SFlorian Hahn typedef T __attribute__((matrix_type(R, C))) type; // expected-error{{invalid matrix element type 's'}}
121ffcaed32SFlorian Hahn };
122ffcaed32SFlorian Hahn
123ffcaed32SFlorian Hahn struct s {};
124ffcaed32SFlorian Hahn
test_make3()125ffcaed32SFlorian Hahn int test_make3() {
126ffcaed32SFlorian Hahn make3<s, 3, 3> x; // expected-note{{in instantiation of}}
127ffcaed32SFlorian Hahn }
128ffcaed32SFlorian Hahn
129ffcaed32SFlorian Hahn template <typename T, T R, unsigned C>
130ffcaed32SFlorian Hahn struct make4 {
131ffcaed32SFlorian Hahn typedef T __attribute__((matrix_type(R, C))) type;
132ffcaed32SFlorian Hahn };
133ffcaed32SFlorian Hahn
test_make4()134ffcaed32SFlorian Hahn int test_make4() {
135ffcaed32SFlorian Hahn make4<int, 4, 5>::type x;
136ffcaed32SFlorian Hahn }
137ffcaed32SFlorian Hahn
138ffcaed32SFlorian Hahn typedef int *int_ptr;
139ffcaed32SFlorian Hahn template <unsigned R, unsigned C>
140ffcaed32SFlorian Hahn struct make5 {
141ffcaed32SFlorian Hahn typedef int_ptr __attribute__((matrix_type(R, C))) type; // expected-error{{invalid matrix element type}}
142ffcaed32SFlorian Hahn };
143ffcaed32SFlorian Hahn
144ffcaed32SFlorian Hahn template <int R, unsigned C>
145ffcaed32SFlorian Hahn struct make6 {
146ffcaed32SFlorian Hahn typedef int __attribute__((matrix_type(R, C))) type;
147ffcaed32SFlorian Hahn };
148ffcaed32SFlorian Hahn
test_make6()149ffcaed32SFlorian Hahn int test_make6() {
150ffcaed32SFlorian Hahn make6<4, 4>::type x;
151ffcaed32SFlorian Hahn
152ffcaed32SFlorian Hahn make6<2, 2>::type y;
153ffcaed32SFlorian Hahn }
154ffcaed32SFlorian Hahn
155ffcaed32SFlorian Hahn namespace Deduction {
156ffcaed32SFlorian Hahn template <typename T>
157ffcaed32SFlorian Hahn struct X0;
158ffcaed32SFlorian Hahn
159ffcaed32SFlorian Hahn template <typename T, unsigned N>
160ffcaed32SFlorian Hahn struct X0<T __attribute__((matrix_type(N, 3)))> {
161ffcaed32SFlorian Hahn static const unsigned value = 0;
162ffcaed32SFlorian Hahn };
163ffcaed32SFlorian Hahn
164ffcaed32SFlorian Hahn template <typename T>
165ffcaed32SFlorian Hahn struct X0<T __attribute__((matrix_type(4, 3)))> {
166ffcaed32SFlorian Hahn static const unsigned value = 1;
167ffcaed32SFlorian Hahn };
168ffcaed32SFlorian Hahn
169ffcaed32SFlorian Hahn template <unsigned N>
170ffcaed32SFlorian Hahn struct X0<float __attribute__((matrix_type(N, 3)))> {
171ffcaed32SFlorian Hahn static const unsigned value = 2;
172ffcaed32SFlorian Hahn };
173ffcaed32SFlorian Hahn
174ffcaed32SFlorian Hahn template <>
175ffcaed32SFlorian Hahn struct X0<float __attribute__((matrix_type(4, 3)))> {
176ffcaed32SFlorian Hahn static const unsigned value = 3;
177ffcaed32SFlorian Hahn };
178ffcaed32SFlorian Hahn
179ffcaed32SFlorian Hahn typedef int __attribute__((matrix_type(2, 3))) int2;
180ffcaed32SFlorian Hahn typedef int __attribute__((matrix_type(4, 3))) int4;
181ffcaed32SFlorian Hahn typedef float __attribute__((matrix_type(2, 3))) float2;
182ffcaed32SFlorian Hahn typedef float __attribute__((matrix_type(4, 3))) float4;
183ffcaed32SFlorian Hahn
184ffcaed32SFlorian Hahn int array0[X0<int2>::value == 0 ? 1 : -1];
185ffcaed32SFlorian Hahn int array1[X0<int4>::value == 1 ? 1 : -1];
186ffcaed32SFlorian Hahn int array2[X0<float2>::value == 2 ? 1 : -1];
187ffcaed32SFlorian Hahn int array3[X0<float4>::value == 3 ? 1 : -1];
188ffcaed32SFlorian Hahn } // namespace Deduction
189