Skip to content

Commit f9785e4

Browse files
committed
[Clang][C++20] Implement constexpr std::bit_cast for bit-fields
After this commit, clang permits constructions like: ```c++ struct bits { unsigned char : 7; unsigned char flag : 1; } static_assert(std::bit_cast<bits>(0x80).flag); // succeeds on little-endian systems ``` This change builds on the prior work in https://reviews.llvm.org/D62825
1 parent f281d34 commit f9785e4

File tree

4 files changed

+690
-117
lines changed

4 files changed

+690
-117
lines changed

clang/include/clang/Basic/DiagnosticASTKinds.td

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -316,10 +316,14 @@ def note_constexpr_memcpy_unsupported : Note<
316316
"size to copy (%4) is not a multiple of size of element type %3 (%5)|"
317317
"source is not a contiguous array of at least %4 elements of type %3|"
318318
"destination is not a contiguous array of at least %4 elements of type %3}2">;
319+
def note_constexpr_bit_cast_bad_bits : Note<
320+
"bit_cast source expression (type %5) does not produce a constant value for "
321+
"%select{bit|byte}0 [%1] (of {%2%plural{0:|:..0}2}) which are required by "
322+
"target type %4 %select{|(subobject %3)}6">;
319323
def note_constexpr_bit_cast_unsupported_type : Note<
320324
"constexpr bit cast involving type %0 is not yet supported">;
321-
def note_constexpr_bit_cast_unsupported_bitfield : Note<
322-
"constexpr bit_cast involving bit-field is not yet supported">;
325+
def note_constexpr_bit_cast_invalid_decl : Note<
326+
"bit_cast here %select{from|to}0 invalid declaration %0">;
323327
def note_constexpr_bit_cast_invalid_type : Note<
324328
"bit_cast %select{from|to}0 a %select{|type with a }1"
325329
"%select{union|pointer|member pointer|volatile|reference}2 "

0 commit comments

Comments
 (0)