blob: f968c13f10238e97c8e349e8e0a35127cd2d273a [file] [log] [blame]
Daniel Dunbara5728872009-12-15 20:14:24 +00001// RUN: %clang_cc1 -fsyntax-only -verify %s
Douglas Gregor9cdda0c2009-06-17 21:51:59 +00002template<typename T, unsigned Length>
3struct make1 {
4 typedef T __attribute__((ext_vector_type(Length))) type;
5};
6
Mike Stumpd1969d82009-07-22 00:43:08 +00007void test_make1() {
Douglas Gregor9cdda0c2009-06-17 21:51:59 +00008 make1<int, 5>::type x;
9 x.x = 4;
10}
11
12template<typename T, unsigned Length>
13struct make2 {
14 typedef T __attribute__((ext_vector_type(Length))) type; // expected-error{{zero vector size}}
15};
16
17int test_make2() {
18 make2<int, 0> x; // expected-note{{in instantiation of}}
19}
20
21template<typename T, unsigned Length>
22struct make3 {
Douglas Gregor27cac992010-06-30 17:30:41 +000023 typedef T __attribute__((ext_vector_type(Length))) type; // expected-error{{invalid vector element type 's'}}
Douglas Gregor9cdda0c2009-06-17 21:51:59 +000024};
25
26struct s {};
27
28int test_make3() {
29 make3<s, 3>x; // expected-note{{in instantiation of}}
30}
31
32template<typename T, T Length>
33struct make4 {
34 typedef T __attribute__((ext_vector_type(Length))) type;
35};
36
37int test_make4() {
38 make4<int, 4>::type x;
39 x.w = 7;
40}
41
42typedef int* int_ptr;
43template<unsigned Length>
44struct make5 {
Douglas Gregor27cac992010-06-30 17:30:41 +000045 typedef int_ptr __attribute__((ext_vector_type(Length))) type; // expected-error{{invalid vector element type}}
Douglas Gregor9cdda0c2009-06-17 21:51:59 +000046};
47
John McCalleee91c32009-10-23 17:55:45 +000048template<int Length>
49struct make6 {
50 typedef int __attribute__((ext_vector_type(Length))) type;
51};
52
53int 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}
Douglas Gregor4ac01402011-06-15 16:02:29 +000061
62namespace 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}