annotate gcc/testsuite/g++.dg/cpp2a/bitfield1.C @ 131:84e7813d76e9

gcc-8.2
author mir3636
date Thu, 25 Oct 2018 07:37:49 +0900
parents 04ced10e8804
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 // P0683R1
kono
parents:
diff changeset
2 // { dg-do run { target c++11 } }
kono
parents:
diff changeset
3 // { dg-options "" }
kono
parents:
diff changeset
4
kono
parents:
diff changeset
5 extern "C" void abort ();
kono
parents:
diff changeset
6 int a;
kono
parents:
diff changeset
7 const int b = 0;
kono
parents:
diff changeset
8 struct S {
kono
parents:
diff changeset
9 int c : 5 = 1; // { dg-warning "default member initializers for bit-fields only available with" "" { target c++17_down } }
kono
parents:
diff changeset
10 int d : 6 { 2 }; // { dg-warning "default member initializers for bit-fields only available with" "" { target c++17_down } }
kono
parents:
diff changeset
11 int e : true ? 7 : a = 3;
kono
parents:
diff changeset
12 int f : (true ? 8 : b) = 4; // { dg-warning "default member initializers for bit-fields only available with" "" { target c++17_down } }
kono
parents:
diff changeset
13 int g : (true ? 9 : b) { 5 }; // { dg-warning "default member initializers for bit-fields only available with" "" { target c++17_down } }
kono
parents:
diff changeset
14 int h : 1 || new int { 0 };
kono
parents:
diff changeset
15 };
kono
parents:
diff changeset
16 #if __cplusplus >= 201402L
kono
parents:
diff changeset
17 static_assert (S{}.c == 1);
kono
parents:
diff changeset
18 static_assert (S{}.d == 2);
kono
parents:
diff changeset
19 static_assert (S{}.e == 0);
kono
parents:
diff changeset
20 static_assert (S{}.f == 4);
kono
parents:
diff changeset
21 static_assert (S{}.g == 5);
kono
parents:
diff changeset
22 static_assert (S{}.h == 0);
kono
parents:
diff changeset
23 #endif
kono
parents:
diff changeset
24 template <bool V, int W>
kono
parents:
diff changeset
25 struct U {
kono
parents:
diff changeset
26 int j : W = 7; // { dg-warning "default member initializers for bit-fields only available with" "" { target c++17_down } }
kono
parents:
diff changeset
27 int k : W { 8 }; // { dg-warning "default member initializers for bit-fields only available with" "" { target c++17_down } }
kono
parents:
diff changeset
28 int l : V ? 7 : a = 3;
kono
parents:
diff changeset
29 int m : (V ? W : b) = 9; // { dg-warning "default member initializers for bit-fields only available with" "" { target c++17_down } }
kono
parents:
diff changeset
30 int n : (V ? W : b) { 10 }; // { dg-warning "default member initializers for bit-fields only available with" "" { target c++17_down } }
kono
parents:
diff changeset
31 int o : 1 || new int { 0 };
kono
parents:
diff changeset
32 };
kono
parents:
diff changeset
33 #if __cplusplus >= 201402L
kono
parents:
diff changeset
34 static_assert (U<true, 12>{}.j == 7);
kono
parents:
diff changeset
35 static_assert (U<true, 13>{}.k == 8);
kono
parents:
diff changeset
36 static_assert (U<true, 10>{}.l == 0);
kono
parents:
diff changeset
37 static_assert (U<true, 11>{}.m == 9);
kono
parents:
diff changeset
38 static_assert (U<true, 8>{}.n == 10);
kono
parents:
diff changeset
39 static_assert (U<true, 7>{}.o == 0);
kono
parents:
diff changeset
40 #endif
kono
parents:
diff changeset
41 S s;
kono
parents:
diff changeset
42 U<true, 10> u;
kono
parents:
diff changeset
43
kono
parents:
diff changeset
44 int
kono
parents:
diff changeset
45 main ()
kono
parents:
diff changeset
46 {
kono
parents:
diff changeset
47 if (s.c != 1 || s.d != 2 || s.e != 0 || s.f != 4 || s.g != 5 || s.h != 0)
kono
parents:
diff changeset
48 abort ();
kono
parents:
diff changeset
49 s.c = 47; // { dg-warning "overflow in conversion from" }
kono
parents:
diff changeset
50 s.d = 47 * 2; // { dg-warning "overflow in conversion from" }
kono
parents:
diff changeset
51 s.e = 47 * 4; // { dg-warning "overflow in conversion from" }
kono
parents:
diff changeset
52 s.f = 47 * 8; // { dg-warning "overflow in conversion from" }
kono
parents:
diff changeset
53 s.g = 47 * 16; // { dg-warning "overflow in conversion from" }
kono
parents:
diff changeset
54 s.h = 2; // { dg-warning "overflow in conversion from" }
kono
parents:
diff changeset
55 if (s.c != 15 || s.d != 15 * 2 || s.e != 15 * 4 || s.f != 15 * 8 || s.g != 15 * 16 || s.h != 0)
kono
parents:
diff changeset
56 abort ();
kono
parents:
diff changeset
57 if (u.j != 7 || u.k != 8 || u.l != 0 || u.m != 9 || u.n != 10 || u.o != 0)
kono
parents:
diff changeset
58 abort ();
kono
parents:
diff changeset
59 u.j = 47 * 32; // { dg-warning "overflow in conversion from" }
kono
parents:
diff changeset
60 u.k = 47 * 32; // { dg-warning "overflow in conversion from" }
kono
parents:
diff changeset
61 u.l = 47 * 4; // { dg-warning "overflow in conversion from" }
kono
parents:
diff changeset
62 u.m = 47 * 32; // { dg-warning "overflow in conversion from" }
kono
parents:
diff changeset
63 u.n = 47 * 32; // { dg-warning "overflow in conversion from" }
kono
parents:
diff changeset
64 u.o = 2; // { dg-warning "overflow in conversion from" }
kono
parents:
diff changeset
65 if (u.j != 15 * 32 || u.k != 15 * 32 || u.l != 15 * 4 || u.m != 15 * 32 || u.n != 15 * 32 || u.o != 0)
kono
parents:
diff changeset
66 abort ();
kono
parents:
diff changeset
67 s.c = 15;
kono
parents:
diff changeset
68 s.d = 15 * 2;
kono
parents:
diff changeset
69 s.e = 15 * 4;
kono
parents:
diff changeset
70 s.f = 16 * 8;
kono
parents:
diff changeset
71 s.g = 15 * 16;
kono
parents:
diff changeset
72 u.j = 15 * 32;
kono
parents:
diff changeset
73 u.k = 15 * 32;
kono
parents:
diff changeset
74 u.l = 15 * 4;
kono
parents:
diff changeset
75 u.m = 15 * 32;
kono
parents:
diff changeset
76 u.n = 15 * 32;
kono
parents:
diff changeset
77 }