The following compile with the C backend but not with C++
import atomics
type
Pledge* {.exportc.} = object
p: PledgePtr
PledgeKind {.exportc.} = enum
Single
Iteration
PledgePtr {.exportc.} = ptr object
case kind: PledgeKind
of Single:
impl: PledgeImpl
of Iteration:
discard
PledgeImpl {.exportc.} = object
fulfilled: Atomic[bool]
var x: Pledge
echo x.repr
C++ code
struct Pledge;
struct tyObject_PledgePtrcolonObjectType___yxB804f8EWpdMmtSWWPeFA;
...
struct PledgeImpl;
struct Pledge {
tyObject_PledgePtrcolonObjectType___yxB804f8EWpdMmtSWWPeFA* p;
};
...
typedef NU8 PledgeKind;
typedef std::atomic<NIM_BOOL> TY__Z2iuRDrwY0WX5bGI2o2sLQ;
struct PledgeImpl {
TY__Z2iuRDrwY0WX5bGI2o2sLQ fulfilled;
};
struct tyObject_PledgePtrcolonObjectType___yxB804f8EWpdMmtSWWPeFA {
PledgeKind kind;
union{
struct {PledgeImpl impl;
};
};
};
Error:
error: member ‘PledgeImpl tyObject_PledgePtrcolonObjectType___yxB804f8EWpdMmtSWWPeFA::<unnamed union>::<unnamed struct>::impl’ with constructor not allowed in anonymous aggregate
75 | struct {PledgeImpl impl;
| ^~~~