[llvm-bugs] [Bug 51925] std::bit_cast falls over, seemingly due to some invisible alignment requirements

via llvm-bugs llvm-bugs at lists.llvm.org
Wed Oct 6 18:11:02 PDT 2021


https://bugs.llvm.org/show_bug.cgi?id=51925

Richard Smith <richard-llvm at metafoo.co.uk> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |INVALID
             Status|NEW                         |RESOLVED

--- Comment #1 from Richard Smith <richard-llvm at metafoo.co.uk> ---
This behavior is correct. Your type `Item` contains 9 bytes with determinate
values, followed by three padding bytes which have indeterminate values, but
your type `Data` contains a 12 byte array. The `bit_cast` therefore leaves the
last three bytes of that array with indeterminate values.

But because `bit_cast` returns by value, this means your program attempts to
copy those three `char` objects that have indeterminate values. Copying an
indeterminate value is only permitted for unsigned narrow character types and
`std::byte`, as the diagnostic says.

So this call to `bit_cast` results in undefined behavior, which means it's not
permitted in a constant expression.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20211007/50383dd0/attachment.html>


More information about the llvm-bugs mailing list