49 lines · cpp
1// RUN: %clang_cc1 %s -Wno-uninitialized -std=c++17 -fsyntax-only -verify2 3namespace Vector {4 5using TwoIntsVecSize __attribute__((vector_size(8))) = int;6 7constexpr TwoIntsVecSize a = {1,2};8static_assert(a[1] == 2);9static_assert(a[2]); // expected-error {{not an integral constant expression}} expected-note {{read of dereferenced one-past-the-end pointer}}10 11constexpr struct {12 TwoIntsVecSize b;13} Val = {{0,1}};14 15static_assert(Val.b[1] == 1);16 17constexpr TwoIntsVecSize c[3] = {{0,1}, {2,3}, {4,5}};18static_assert(c[0][0] == 0);19static_assert(c[1][1] == 3);20static_assert(c[2][3]); // expected-error {{not an integral constant expression}} expected-note {{cannot refer to element 3 of array of 2 elements}}21 22// make sure clang rejects taking address of a vector element23static_assert(&a[0]); // expected-error {{address of vector element requested}}24 25}26 27namespace ExtVector {28 29using FourIntsExtVec __attribute__((ext_vector_type(4))) = int;30 31constexpr FourIntsExtVec b = {1,2,3,4};32static_assert(b[0] == 1 && b[1] == 2 && b[2] == 3 && b[3] == 4);33static_assert(b.s0 == 1 && b.s1 == 2 && b.s2 == 3 && b.s3 == 4);34static_assert(b.x == 1 && b.y == 2 && b.z == 3 && b.w == 4);35static_assert(b.r == 1 && b.g == 2 && b.b == 3 && b.a == 4);36static_assert(b[5]); // expected-error {{not an integral constant expression}} expected-note {{cannot refer to element 5 of array of 4 elements}}37 38// FIXME: support selecting multiple elements39static_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);42 43// make sure clang rejects taking address of a vector element44static_assert(&b[1]); // expected-error {{address of vector element requested}}45 46constexpr const FourIntsExtVec *p = &b;47static_assert(p->x == 1);48}49