Debian Codegraph @

gcc/testsuite/g++.dg/cpp/embed-4.C

raw
1 // { dg-do run { target c++11 } }
2 // { dg-options "" }
3
4 constexpr unsigned char a[] = {
5 #embed __FILE__
6 };
7
8 constexpr unsigned char
9 foo (int x)
10 {
11 return a[x];
12 }
13 constexpr unsigned char b = a[32];
14 constexpr unsigned char c = foo (42);
15
16 #if __cplusplus >= 201402L
17 constexpr bool
18 bar ()
19 {
20 unsigned char d[] = {
21 #embed __FILE__
22 };
23 d[42] = ' ';
24 d[32] = 'X';
25 d[0] = d[1] + 16;
26 d[sizeof (d) - 1] = d[42] - ' ';
27 for (int i = 0; i < sizeof (d); ++i)
28 switch (i)
29 {
30 case 0:
31 if (d[i] != a[1] + 16)
32 return false;
33 break;
34 case 32:
35 if (d[i] != 'X')
36 return false;
37 break;
38 case 42:
39 if (d[i] != ' ')
40 return false;
41 break;
42 case sizeof (d) - 1:
43 if (d[i] != 0)
44 return false;
45 break;
46 default:
47 if (d[i] != a[i])
48 return false;
49 break;
50 }
51 return true;
52 }
53
54 static_assert (bar (), "");
55 #endif
56
57 int
58 main ()
59 {
60 unsigned char e[] = {
61 #embed __FILE__
62 };
63
64 if (b != e[32] || c != e[42])
65 __builtin_abort ();
66 }