On 27/08/20 12:46 +0200, Jakub Jelinek wrote:
On Thu, Aug 27, 2020 at 12:06:13PM +0200, Jakub Jelinek via Gcc-patches wrote:

Oops, rewrote the testcase from __builtin_bit_cast to std::bit_cast without
adjusting the syntax properly.
Also, let's not use bitfields in there, as clang doesn't support those.
So, adjusted testcase below.  clang++ rejects all 6 of those, but from what
you said, I'd expect that u and z should be well defined.

#include <bit>

struct S { short a; int b; };
struct T { int a, b; };

constexpr int
foo ()
{
 S a = S ();
 S b = { 0, 0 };
 S c = a;
 S d;
 S e;
 d = a;
 e = S ();
 int u = std::bit_cast<T> (a).a; // Is this well defined due to value 
initialization of a?

The standard says that padding bits in the bit_cast result are
unspecified, so I don't think they have to be copied even if the
source object was zero-initialized and has all-zero padding bits.

Reply via email to