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