dmd/compiler/test/runnable_cxx/extra-files/cpp_nonpod_byval.cpp
Tim Schendekehl 56a21cba42 Fix bugzilla 24577 - Struct with constructor returned from C++ wrong
The test case is copied from LDC, where it already worked. It also has
an additional test for a member struct with constructor.
2024-06-08 15:47:29 +02:00

74 lines
1.2 KiB
C++

extern "C" int printf(const char *, ...);
#define Foo(T) \
T fooD(T param); \
T fooCpp(T param) \
{ \
printf("fooCpp %d [%p]\n", param.a, &param); \
return fooD(T{2 * param.a}); \
}
struct POD
{
int a;
};
Foo(POD);
struct CtorOnly
{
int a;
CtorOnly() : a(0) {}
CtorOnly(int a) : a(a) {}
};
Foo(CtorOnly);
struct DtorOnly
{
int a;
~DtorOnly(); // implemented in D
};
Foo(DtorOnly);
struct CtorDtor
{
int a;
CtorDtor(int a) : a(a) {}
~CtorDtor(); // implemented in D
};
Foo(CtorDtor);
struct Copy
{
int a;
Copy(int a) : a(a) {}
~Copy(); // implemented in D
Copy(const Copy &rhs) : a(rhs.a) { printf("cppcpy %d [%p]\n", a, this); }
};
Foo(Copy);
struct CopyAndMove
{
int a;
CopyAndMove(int a) : a(a) {}
~CopyAndMove(); // implemented in D
CopyAndMove(const CopyAndMove &rhs) : a(rhs.a) { printf("cppcpy %d [%p]\n", a, this); }
CopyAndMove(CopyAndMove &&) = default;
};
Foo(CopyAndMove);
struct MoveOnly
{
int a;
MoveOnly(int a) : a(a) {}
~MoveOnly(); // implemented in D
MoveOnly(const MoveOnly &) = delete;
MoveOnly(MoveOnly &&) = default;
};
Foo(MoveOnly);
struct MemberWithCtor
{
int a;
CtorOnly m;
};
Foo(MemberWithCtor);