aboutsummaryrefslogtreecommitdiff
path: root/gcc/cp/tree.c
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2021-12-04 11:02:15 +0100
committerJakub Jelinek <jakub@redhat.com>2021-12-04 11:02:15 +0100
commitc57c910c945ac68ba9a7cda9b0f963173781d58c (patch)
tree32117623ca59d79f56b51c0f039a0081802a184d /gcc/cp/tree.c
parent55dfce4d5cb4a366ced7e1194a1c7f04389e3087 (diff)
downloadgcc-c57c910c945ac68ba9a7cda9b0f963173781d58c.zip
gcc-c57c910c945ac68ba9a7cda9b0f963173781d58c.tar.gz
gcc-c57c910c945ac68ba9a7cda9b0f963173781d58c.tar.bz2
c++: Allow indeterminate unsigned char or std::byte in bit_cast - P1272R4
P1272R4 has added to the std::byteswap new stuff to me quite unrelated clarification for std::bit_cast. The patch treats it as DR, applying to all languages. We no longer diagnose if padding bits are stored into unsigned char or std::byte result, fields or bitfields, instead arrange for that result, those fields or bitfields to get indeterminate value (empty CONSTRUCTOR with CONSTRUCTOR_NO_ZEROING or just leaving the member's initializer out and setting CONSTRUCTOR_NO_ZEROING on parent). We still have a bug that we don't diagnose in lots of places lvalue-to-rvalue conversions of indeterminate values or class objects with some indeterminate members. 2021-12-04 Jakub Jelinek <jakub@redhat.com> * cp-tree.h (is_byte_access_type_not_plain_char): Declare. * tree.c (is_byte_access_type_not_plain_char): New function. * constexpr.c (clear_uchar_or_std_byte_in_mask): New function. (cxx_eval_bit_cast): Don't error about padding bits if target type is unsigned char or std::byte, instead return no clearing ctor. Use clear_uchar_or_std_byte_in_mask. * g++.dg/cpp2a/bit-cast11.C: New test. * g++.dg/cpp2a/bit-cast12.C: New test. * g++.dg/cpp2a/bit-cast13.C: New test. * g++.dg/cpp2a/bit-cast14.C: New test.
Diffstat (limited to 'gcc/cp/tree.c')
-rw-r--r--gcc/cp/tree.c12
1 files changed, 12 insertions, 0 deletions
diff --git a/gcc/cp/tree.c b/gcc/cp/tree.c
index 1471ed8..52c5683 100644
--- a/gcc/cp/tree.c
+++ b/gcc/cp/tree.c
@@ -4311,6 +4311,18 @@ is_byte_access_type (tree type)
&& !strcmp ("byte", TYPE_NAME_STRING (type)));
}
+/* Returns true if TYPE is unsigned char or std::byte. */
+
+bool
+is_byte_access_type_not_plain_char (tree type)
+{
+ type = TYPE_MAIN_VARIANT (type);
+ if (type == char_type_node)
+ return false;
+
+ return is_byte_access_type (type);
+}
+
/* Returns 1 iff type T is something we want to treat as a scalar type for
the purpose of deciding whether it is trivial/POD/standard-layout. */