]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/testsuite/g++.dg/cpp0x/constexpr-fold1.C
Regenerate riscv.opt.urls and i386.opt.urls
[thirdparty/gcc.git] / gcc / testsuite / g++.dg / cpp0x / constexpr-fold1.C
CommitLineData
894bec68
MP
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
8constexpr char s[] = "abc";
9constexpr int t[] = { 'a', 'b', 'c', '\0' };
10
11constexpr char
12fn1 (const char *p)
13{
14 return *(p + 1);
15}
16
17constexpr char
18fn2 (const char *p)
19{
20 return p[1];
21}
22
23constexpr int
24fn3 (const int *p)
25{
26 return *(p + 1);
27}
28
29constexpr int
30fn4 (const int *p)
31{
32 return p[1];
33}
34
35constexpr auto c1 = fn1 (&s[0]);
36constexpr auto c2 = fn1 (&s[1]);
37constexpr auto c3 = fn1 (&s[2]);
38
39SA (c1 == 'b');
40SA (c2 == 'c');
41SA (c3 == '\0');
42
43constexpr auto d1 = fn2 (&s[0]);
44constexpr auto d2 = fn2 (&s[1]);
45constexpr auto d3 = fn2 (&s[2]);
46
47SA (d1 == 'b');
48SA (d2 == 'c');
49SA (d3 == '\0');
50
51constexpr auto e1 = fn3 (&t[0]);
52constexpr auto e2 = fn3 (&t[1]);
53constexpr auto e3 = fn3 (&t[2]);
54
55SA (e1 == 'b');
56SA (e2 == 'c');
57SA (e3 == '\0');
58
59constexpr auto f1 = fn4 (&t[0]);
60constexpr auto f2 = fn4 (&t[1]);
61constexpr auto f3 = fn4 (&t[2]);
62
63SA (f1 == 'b');
64SA (f2 == 'c');
65SA (f3 == '\0');