1 // RUN: %clang_cc1 %s -Wno-uninitialized -std=c++17 -fsyntax-only -verify
5 using TwoIntsVecSize
__attribute__((vector_size(8))) = int;
7 constexpr TwoIntsVecSize a
= {1,2};
8 static_assert(a
[1] == 2);
9 static_assert(a
[2]); // expected-error {{not an integral constant expression}} expected-note {{read of dereferenced one-past-the-end pointer}}
15 static_assert(Val
.b
[1] == 1);
17 constexpr TwoIntsVecSize c
[3] = {{0,1}, {2,3}, {4,5}};
18 static_assert(c
[0][0] == 0);
19 static_assert(c
[1][1] == 3);
20 static_assert(c
[2][3]); // expected-error {{not an integral constant expression}} expected-note {{cannot refer to element 3 of array of 2 elements}}
22 // make sure clang rejects taking address of a vector element
23 static_assert(&a
[0]); // expected-error {{address of vector element requested}}
29 using FourIntsExtVec
__attribute__((ext_vector_type(4))) = int;
31 constexpr FourIntsExtVec b
= {1,2,3,4};
32 static_assert(b
[0] == 1 && b
[1] == 2 && b
[2] == 3 && b
[3] == 4);
33 static_assert(b
.s0
== 1 && b
.s1
== 2 && b
.s2
== 3 && b
.s3
== 4);
34 static_assert(b
.x
== 1 && b
.y
== 2 && b
.z
== 3 && b
.w
== 4);
35 static_assert(b
.r
== 1 && b
.g
== 2 && b
.b
== 3 && b
.a
== 4);
36 static_assert(b
[5]); // expected-error {{not an integral constant expression}} expected-note {{cannot refer to element 5 of array of 4 elements}}
38 // FIXME: support selecting multiple elements
39 static_assert(b
.lo
.lo
== 1); // expected-error {{not an integral constant expression}}
40 // static_assert(b.lo.lo==1 && b.lo.hi==2 && b.hi.lo == 3 && b.hi.hi == 4);
41 // static_assert(b.odd[0]==1 && b.odd[1]==2 && b.even[0] == 3 && b.even[1] == 4);
43 // make sure clang rejects taking address of a vector element
44 static_assert(&b
[1]); // expected-error {{address of vector element requested}}