Debian Codegraph @

clang/test/SemaTemplate/ext-vector-type.cpp

raw
1 // RUN: %clang_cc1 -fsyntax-only -verify %s
2 template<typename T, unsigned Length>
3 struct make1 {
4 typedef T __attribute__((ext_vector_type(Length))) type;
5 };
6
7 void test_make1() {
8 make1<int, 5>::type x;
9 x.x = 4;
10 }
11
12 template<typename T, unsigned Length>
13 struct make2 {
14 typedef T __attribute__((ext_vector_type(Length))) type; // expected-error{{zero vector size}}
15 };
16
17 int test_make2() {
18 make2<int, 0> x; // expected-note{{in instantiation of}}
19 }
20
21 template<typename T, unsigned Length>
22 struct make3 {
23 typedef T __attribute__((ext_vector_type(Length))) type; // expected-error{{invalid vector element type 's'}}
24 };
25
26 struct s {};
27
28 int test_make3() {
29 make3<s, 3>x; // expected-note{{in instantiation of}}
30 }
31
32 template<typename T, T Length>
33 struct make4 {
34 typedef T __attribute__((ext_vector_type(Length))) type;
35 };
36
37 int test_make4() {
38 make4<int, 4>::type x;
39 x.w = 7;
40 }
41
42 typedef int* int_ptr;
43 template<unsigned Length>
44 struct make5 {
45 typedef int_ptr __attribute__((ext_vector_type(Length))) type; // expected-error{{invalid vector element type}}
46 };
47
48 template<int Length>
49 struct make6 {
50 typedef int __attribute__((ext_vector_type(Length))) type;
51 };
52
53 int test_make6() {
54 make6<4>::type x;
55 x.w = 7;
56
57 make6<2>::type y;
58 y.x = -1;
59 y.w = -1; // expected-error{{vector component access exceeds type}}
60 }
61
62 namespace Deduction {
63 template<typename T> struct X0;
64
65 template<typename T, unsigned N>
66 struct X0<T __attribute__((ext_vector_type(N)))> {
67 static const unsigned value = 0;
68 };
69
70 template<typename T>
71 struct X0<T __attribute__((ext_vector_type(4)))> {
72 static const unsigned value = 1;
73 };
74
75 template<unsigned N>
76 struct X0<float __attribute__((ext_vector_type(N)))> {
77 static const unsigned value = 2;
78 };
79
80 template<>
81 struct X0<float __attribute__((ext_vector_type(4)))> {
82 static const unsigned value = 3;
83 };
84
85 typedef int __attribute__((ext_vector_type(2))) int2;
86 typedef int __attribute__((ext_vector_type(4))) int4;
87 typedef float __attribute__((ext_vector_type(2))) float2;
88 typedef float __attribute__((ext_vector_type(4))) float4;
89
90 int array0[X0<int2>::value == 0? 1 : -1];
91 int array1[X0<int4>::value == 1? 1 : -1];
92 int array2[X0<float2>::value == 2? 1 : -1];
93 int array3[X0<float4>::value == 3? 1 : -1];
94 }