mirror of
https://github.com/dlang/dmd.git
synced 2025-04-26 05:00:16 +03:00

Issue 20339: isPOD returns true if sizeof is accessed inside struct declaration Issue 24292: Struct with destructor wrongly returned in register Function StructDeclaration.isPOD can be called before the semantic run for the struct is finished. It then uses incomplete information about destructors, postblits and copy constructors. The result of isPOD is cached, so later calls will also return the wrong result. This commit changes isPOD, so it uses variables, which are already filled before the semantic run.
50 lines
1.1 KiB
D
50 lines
1.1 KiB
D
// EXTRA_CPP_SOURCES: test24292.cpp
|
|
|
|
extern(C++) struct List(T)
|
|
{
|
|
// Any of the following static ifs can trigger the problem.
|
|
static if (T.sizeof > 4) {}
|
|
static if (__traits(isZeroInit, T)) {}
|
|
static if (__traits(isPOD, T)) {}
|
|
|
|
T* begin;
|
|
}
|
|
|
|
extern(C++) struct StructWithDestructor
|
|
{
|
|
~this();
|
|
|
|
alias L = List!StructWithDestructor;
|
|
int i;
|
|
}
|
|
|
|
extern(C++) struct StructWithCopyCtor
|
|
{
|
|
this(ref const(StructWithCopyCtor));
|
|
|
|
alias L = List!StructWithCopyCtor;
|
|
int i;
|
|
}
|
|
|
|
extern(D) struct StructWithPostblit
|
|
{
|
|
this(this) {}
|
|
|
|
alias L = List!StructWithPostblit;
|
|
int i;
|
|
}
|
|
|
|
static assert(!__traits(isPOD, StructWithDestructor));
|
|
static assert(!__traits(isPOD, StructWithCopyCtor));
|
|
static assert(!__traits(isPOD, StructWithPostblit));
|
|
|
|
extern(C++) StructWithDestructor getStructWithDestructor();
|
|
extern(C++) StructWithCopyCtor getStructWithCopyCtor();
|
|
|
|
void main()
|
|
{
|
|
StructWithDestructor structWithDestructor = getStructWithDestructor();
|
|
assert(structWithDestructor.i == 12345);
|
|
StructWithCopyCtor structWithCopyCtor = getStructWithCopyCtor();
|
|
assert(structWithCopyCtor.i == 54321);
|
|
}
|