Debian Codegraph @

gcc/testsuite/g++.dg/cpp2a/bit-cast14.C

raw
1 // P1272R4
2 // { dg-do compile { target c++14 } }
3
4 struct S { unsigned char a : 8, b : 5, c : 3, d, e; unsigned int f : 8, g : 24; };
5 struct T1 { unsigned char a : 1, : 7, b : 5, c : 3, d, e; unsigned int f : 8, g : 24; };
6 struct T2 { unsigned char a : 8, b : 1, : 4, c : 3, d, e; unsigned int f : 8, g : 24; };
7 struct T3 { unsigned char a : 8, b : 5, c : 1, : 2, d, e; unsigned int f : 8, g : 24; };
8 struct T4 { unsigned char a : 8, b : 5, c : 3, d, e; unsigned int f : 1, : 7, g : 24; };
9
10 constexpr bool
11 f1 ()
12 {
13 T1 t = { 0, 0, 0, 0, 0, 0, 0 };
14 S s = __builtin_bit_cast (S, t);
15 return true;
16 }
17
18 constexpr bool
19 f2 ()
20 {
21 T2 t = { 0, 0, 0, 0, 0, 0, 0 };
22 S s = __builtin_bit_cast (S, t);
23 return true;
24 }
25
26 constexpr bool
27 f3 ()
28 {
29 T3 t = { 0, 0, 0, 0, 0, 0, 0 };
30 S s = __builtin_bit_cast (S, t);
31 return true;
32 }
33
34 constexpr bool
35 f4 ()
36 {
37 T4 t = { 0, 0, 0, 0, 0, 0, 0 };
38 S s = __builtin_bit_cast (S, t); // { dg-error "accessing uninitialized byte" }
39 return true;
40 }
41
42 constexpr bool
43 f5 ()
44 {
45 T1 t = { 0, 0, 0, 0, 0, 0, 0 };
46 S s = __builtin_bit_cast (S, t);
47 unsigned char a = s.a; // { dg-error "accessing uninitialized member" }
48 return true;
49 }
50
51 constexpr bool
52 f6 ()
53 {
54 T2 t = { 0, 0, 0, 0, 0, 0, 0 };
55 S s = __builtin_bit_cast (S, t);
56 unsigned char b = s.b; // { dg-error "accessing uninitialized member" }
57 return true;
58 }
59
60 constexpr bool
61 f7 ()
62 {
63 T3 t = { 0, 0, 0, 0, 0, 0, 0 };
64 S s = __builtin_bit_cast (S, t);
65 unsigned char c = s.c; // { dg-error "accessing uninitialized member" }
66 return true;
67 }
68
69 constexpr bool a = f1 ();
70 constexpr bool b = f2 ();
71 constexpr bool c = f3 ();
72 constexpr bool d = f4 (); // { dg-message "in .constexpr. expansion" }
73 constexpr bool e = f5 (); // { dg-message "in .constexpr. expansion" }
74 constexpr bool f = f6 (); // { dg-message "in .constexpr. expansion" }
75 constexpr bool g = f7 (); // { dg-message "in .constexpr. expansion" }