Files
cbindgen/tests/expectations/enum.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

136 lines
1.4 KiB
C++

#include <cstdarg>
#include <cstdint>
#include <cstdlib>
#include <new>
enum class A : uint32_t {
a1 = 0,
a2 = 2,
a3,
a4 = 5,
};
enum class B : uint16_t {
b1 = 0,
b2 = 2,
b3,
b4 = 5,
};
enum class C : uint8_t {
c1 = 0,
c2 = 2,
c3,
c4 = 5,
};
enum class D : uintptr_t {
d1 = 0,
d2 = 2,
d3,
d4 = 5,
};
enum class E : intptr_t {
e1 = 0,
e2 = 2,
e3,
e4 = 5,
};
enum class K {
k1,
k2,
k3,
k4,
};
enum class L : int8_t {
l1 = -1,
l2 = 0,
l3 = 1,
};
struct I;
struct J;
struct Opaque;
union F {
enum class Tag : uint8_t {
Foo,
Bar,
Baz,
};
struct Foo_Body {
Tag tag;
int16_t _0;
};
struct Bar_Body {
Tag tag;
uint8_t x;
int16_t y;
};
struct {
Tag tag;
};
Foo_Body foo;
Bar_Body bar;
};
struct G {
enum class Tag {
G_Foo,
G_Bar,
G_Baz,
};
struct G_Foo_Body {
int16_t _0;
};
struct G_Bar_Body {
uint8_t x;
int16_t y;
};
Tag tag;
union {
G_Foo_Body foo;
G_Bar_Body bar;
};
};
struct H {
enum class Tag : uint8_t {
H_Foo,
H_Bar,
H_Baz,
};
struct H_Foo_Body {
int16_t _0;
};
struct H_Bar_Body {
uint8_t x;
int16_t y;
};
Tag tag;
union {
H_Foo_Body foo;
H_Bar_Body bar;
};
};
extern "C" {
void root(Opaque *o, A a, B b, C c, D d, E e, F f, G g, H h, I i, J j, K k, L l);
} // extern "C"