Files
cbindgen/tests/expectations/alias.cpp
T
Emilio Cobos Álvarez b2e224354b Use placement new for constructing in tagged unions' helper methods.
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 :)
2019-05-10 18:15:39 +02:00

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"