aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gcc/fold-const.c1
-rw-r--r--gcc/testsuite/g++.dg/cpp2a/bit-cast7.C39
2 files changed, 40 insertions, 0 deletions
diff --git a/gcc/fold-const.c b/gcc/fold-const.c
index 1241b13..81467f1 100644
--- a/gcc/fold-const.c
+++ b/gcc/fold-const.c
@@ -8256,6 +8256,7 @@ native_encode_initializer (tree init, unsigned char *ptr, int len,
{
cnt--;
field = fld;
+ pos = int_byte_position (field);
val = build_zero_cst (TREE_TYPE (fld));
if (TREE_CODE (val) == CONSTRUCTOR)
to_free = val;
diff --git a/gcc/testsuite/g++.dg/cpp2a/bit-cast7.C b/gcc/testsuite/g++.dg/cpp2a/bit-cast7.C
new file mode 100644
index 0000000..4a3c682
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp2a/bit-cast7.C
@@ -0,0 +1,39 @@
+// PR c++/98193
+// { dg-do compile { target c++20 } }
+
+template <typename To, typename From>
+constexpr To
+bit_cast (const From &from)
+{
+ return __builtin_bit_cast (To, from);
+}
+
+struct J
+{
+ long int a, b : 11, h;
+};
+
+struct K
+{
+ long int a, b : 11, c;
+ constexpr bool operator == (const K &x)
+ {
+ return a == x.a && b == x.b && c == x.c;
+ }
+};
+
+struct L
+{
+ long long int a, b : 11, h;
+};
+struct M
+{
+ long long int a, b : 11, c;
+ constexpr bool operator == (const M &x)
+ {
+ return a == x.a && b == x.b && c == x.c;
+ }
+};
+
+static_assert (bit_cast <K> (J{}) == K{}, "");
+static_assert (bit_cast <M> (L{0x0feedbacdeadbeefLL}) == M{0x0feedbacdeadbeefLL}, "");