b2e224354b
Using operator= is not quite sound in presence of destructors and operator overloading. It's perfectly fine to assume that the left-hand-side of an operator= expression is valid memory, however we're using uninitialized memory here, that may not be the case. Use placement new to properly construct tagged unions. I don't need this with any urgency, but it's the right thing to do in presence of complex types, and the current code seems a bomb waiting to explode :)
36 lines
429 B
C++
36 lines
429 B
C++
#include <cstdarg>
|
|
#include <cstdint>
|
|
#include <cstdlib>
|
|
#include <new>
|
|
|
|
enum class Status : uint32_t {
|
|
Ok,
|
|
Err,
|
|
};
|
|
|
|
struct Dep {
|
|
int32_t a;
|
|
float b;
|
|
};
|
|
|
|
template<typename X>
|
|
struct Foo {
|
|
X a;
|
|
X b;
|
|
Dep c;
|
|
};
|
|
|
|
using IntFoo = Foo<int32_t>;
|
|
|
|
using DoubleFoo = Foo<double>;
|
|
|
|
using Unit = int32_t;
|
|
|
|
using SpecialStatus = Status;
|
|
|
|
extern "C" {
|
|
|
|
void root(IntFoo x, DoubleFoo y, Unit z, SpecialStatus w);
|
|
|
|
} // extern "C"
|