https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105260
--- Comment #5 from m.cencora at gmail dot com ---
I've slighlty refactored the code, to remove the auto variables. This issue
remains
#include <new>
inline unsigned deserializeUInt(const unsigned char* &in)
{
unsigned out;
__builtin_memcpy(&out, in, sizeof(out));
in += sizeof(out);
out = __builtin_bswap32(out);
return out;
}
struct Foo
{
unsigned a;
unsigned b;
static Foo deserialize(const unsigned char* &in)
{
return Foo{
deserializeUInt(in),
deserializeUInt(in)
};
}
};
struct Result
{
unsigned idx;
union
{
unsigned a;
const void* ptr;
};
};
Result dummyFunc(Foo);
void deserializeAndInvoke(const unsigned char* it)
{
#ifndef WORKAROUND
union NoDestroy
{
~NoDestroy() {}
Foo value;
};
NoDestroy un{
Foo::deserialize(it)
};
dummyFunc(un.value);
#elif WORKAROUND == 1
union NoDestroy
{
Foo value;
};
NoDestroy un{
Foo::deserialize(it)
};
dummyFunc(un.value);
#elif WORKAROUND == 2
alignas(Foo) char rawStorage[sizeof(Foo)];
Foo* foo = new (&rawStorage[0]) Foo{
Foo::deserialize(it)
};
dummyFunc(*foo);
#endif
}