111
|
1 // PR c++/65642
|
|
2 // { dg-do compile { target c++11 } }
|
|
3
|
|
4 // Check we're able to evaluate these.
|
|
5
|
|
6 #define SA(X) static_assert((X),#X)
|
|
7
|
|
8 constexpr char s[] = "abc";
|
|
9 constexpr int t[] = { 'a', 'b', 'c', '\0' };
|
|
10
|
|
11 constexpr char
|
|
12 fn1 (const char *p)
|
|
13 {
|
|
14 return *(p + 1);
|
|
15 }
|
|
16
|
|
17 constexpr char
|
|
18 fn2 (const char *p)
|
|
19 {
|
|
20 return p[1];
|
|
21 }
|
|
22
|
|
23 constexpr int
|
|
24 fn3 (const int *p)
|
|
25 {
|
|
26 return *(p + 1);
|
|
27 }
|
|
28
|
|
29 constexpr int
|
|
30 fn4 (const int *p)
|
|
31 {
|
|
32 return p[1];
|
|
33 }
|
|
34
|
|
35 constexpr auto c1 = fn1 (&s[0]);
|
|
36 constexpr auto c2 = fn1 (&s[1]);
|
|
37 constexpr auto c3 = fn1 (&s[2]);
|
|
38
|
|
39 SA (c1 == 'b');
|
|
40 SA (c2 == 'c');
|
|
41 SA (c3 == '\0');
|
|
42
|
|
43 constexpr auto d1 = fn2 (&s[0]);
|
|
44 constexpr auto d2 = fn2 (&s[1]);
|
|
45 constexpr auto d3 = fn2 (&s[2]);
|
|
46
|
|
47 SA (d1 == 'b');
|
|
48 SA (d2 == 'c');
|
|
49 SA (d3 == '\0');
|
|
50
|
|
51 constexpr auto e1 = fn3 (&t[0]);
|
|
52 constexpr auto e2 = fn3 (&t[1]);
|
|
53 constexpr auto e3 = fn3 (&t[2]);
|
|
54
|
|
55 SA (e1 == 'b');
|
|
56 SA (e2 == 'c');
|
|
57 SA (e3 == '\0');
|
|
58
|
|
59 constexpr auto f1 = fn4 (&t[0]);
|
|
60 constexpr auto f2 = fn4 (&t[1]);
|
|
61 constexpr auto f3 = fn4 (&t[2]);
|
|
62
|
|
63 SA (f1 == 'b');
|
|
64 SA (f2 == 'c');
|
|
65 SA (f3 == '\0');
|