c++: Allow indeterminate unsigned char or std::byte in bit_cast - P1272R4
authorJakub Jelinek <jakub@redhat.com>
Sat, 4 Dec 2021 10:02:15 +0000 (11:02 +0100)
committerJakub Jelinek <jakub@redhat.com>
Sat, 4 Dec 2021 10:02:15 +0000 (11:02 +0100)
commitc57c910c945ac68ba9a7cda9b0f963173781d58c
tree32117623ca59d79f56b51c0f039a0081802a184d
parent55dfce4d5cb4a366ced7e1194a1c7f04389e3087
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.
gcc/cp/constexpr.c
gcc/cp/cp-tree.h
gcc/cp/tree.c
gcc/testsuite/g++.dg/cpp2a/bit-cast11.C [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp2a/bit-cast12.C [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp2a/bit-cast13.C [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp2a/bit-cast14.C [new file with mode: 0644]