Debian Codegraph @

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

raw
1 // P1272R4
2 // { dg-do compile { target c++14 } }
3
4 struct S { char a[2]; alignas(sizeof 0) int b; };
5 struct T { char a; alignas(sizeof 0) int b; };
6 struct U { char a : 1; char : 6; char b : 1; };
7 struct V { int a; S b; };
8 struct W { unsigned a; T b; };
9
10 constexpr bool
11 f1 ()
12 {
13 T t = { 1, 2 };
14 S s = __builtin_bit_cast (S, t); // { dg-error "accessing uninitialized byte" }
15 return s.a[0] == 1;
16 }
17
18 constexpr bool
19 f2 ()
20 {
21 U u = { 0, 0 };
22 char a = __builtin_bit_cast (char, u); // { dg-error "accessing uninitialized byte" }
23 return true;
24 }
25
26 constexpr bool
27 f3 ()
28 {
29 T t = { 1, 2 };
30 S s = __builtin_bit_cast (S, t); // { dg-error "accessing uninitialized byte" }
31 return s.a[1] == 0;
32 }
33
34 constexpr bool
35 f4 ()
36 {
37 U u = { 0, 0 };
38 char a = __builtin_bit_cast (char, u); // { dg-error "accessing uninitialized byte" }
39 return a == 0;
40 }
41
42 constexpr bool
43 f5 ()
44 {
45 W t = { 1, 2 };
46 V s = __builtin_bit_cast (V, t); // { dg-error "accessing uninitialized byte" }
47 return s.b.a[0] == 1;
48 }
49
50 constexpr bool
51 f6 ()
52 {
53 W t = { 1, 2 };
54 V s = __builtin_bit_cast (V, t); // { dg-error "accessing uninitialized byte" }
55 return s.b.a[1] == 1;
56 }
57
58 constexpr bool a = f1 ();
59 constexpr bool b = f2 ();
60 constexpr bool c = f3 ();
61 constexpr bool d = f4 ();
62 constexpr bool e = f5 ();
63 constexpr bool f = f6 ();