PR c++/83993
[official-gcc.git] / gcc / testsuite / g++.dg / cpp0x / pr83993.C
blob17b7a6419578de7074277ad7dc99603954b01ffb
1 // PR c++/83993
2 // { dg-do compile { target c++11 } }
3 // { dg-options "" }
5 extern const int a[];
6 const int b[5] = { 1, 2, 3, 4, 5 };
7 extern const int c[4];
8 constexpr const int *d = &a[0];
9 constexpr const int *d2 = a;
10 constexpr const int *e = &a[1];         // { dg-error "non-zero array subscript '1' is used with array 'a' of type 'const int \\\[\\\]' with unknown bounds" }
11 constexpr const int *f = &b[0];
12 constexpr const int *f2 = b;
13 constexpr const int *g = &b[5];
14 constexpr const int *h = &b[6];         // { dg-error "array subscript value '6' is outside the bounds of array 'b' of type 'const int \\\[5\\\]'" }
15 constexpr const int *i = &c[0];
16 constexpr const int *i2 = c;
17 constexpr const int *j = &c[4];
18 constexpr const int *k = &c[5];         // { dg-error "array subscript value '5' is outside the bounds of array 'c' of type 'const int \\\[4\\\]'" }
19 extern const int l[];
21 void
22 foo ()
24   extern const int l[3];
25   constexpr const int *m = &l[0];
26   constexpr const int *m2 = l;
27   constexpr const int *n = &l[1];
28   static_assert (m == m2, "");
31 constexpr const int *m = &l[0];
32 constexpr const int *m2 = l;
33 constexpr const int *n = &l[1];         // { dg-error "non-zero array subscript '1' is used with array 'l' of type 'const int \\\[\\\]' with unknown bounds" }
34 static_assert (d == d2 && f == f2 && i == i2 && m == m2, "");
35 const int o[] = { 1, 2 };
36 constexpr const int *p = &o[0];
37 constexpr const int *p2 = o;
38 constexpr const int *q = &o[2];
39 constexpr const int *r = &o[3];         // { dg-error "array subscript value '3' is outside the bounds of array 'o' of type 'const int \\\[2\\\]'" }
40 struct S { char a; char b[]; } s;
41 constexpr const char *t = &s.b[0];
42 constexpr const char *t2 = s.b;
43 constexpr const char *u = &s.b[1];      // { dg-error "non-zero array subscript '1' is used with array of type 'char \\\[\\\]' with unknown bounds" }
44 struct V { int a; };
45 extern V v[];
46 constexpr V *w = &v[0];
47 constexpr V *w2 = v;
48 constexpr int *x = &v[0].a;
49 constexpr int y = a[0];                 // { dg-error "the value of 'a' is not usable in a constant expression" }