Fix bugzilla issue 24596: std.typecons.Rebindable2: Don't destroy classes! Only destroy structs! (#9012)

This commit is contained in:
FeepingCreature 2024-06-10 17:10:18 +02:00 committed by GitHub
parent aee2a7b760
commit 539dc473ba
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 19 additions and 1 deletions

View file

@ -3873,6 +3873,21 @@ if (isInputRange!Range && !isInfinite!Range &&
assert([BigInt(2), BigInt(3)].maxElement == BigInt(3));
}
// https://issues.dlang.org/show_bug.cgi?id=24596
@safe unittest
{
static class A {
int i;
int getI() @safe => i;
this(int i) @safe { this.i = i; }
}
auto arr = [new A(2), new A(3)];
arr.maxElement!(a => a.getI);
assert(arr[0].getI == 2);
}
// minPos
/**
Computes a subrange of `range` starting at the first occurrence of `range`'s

View file

@ -3125,7 +3125,10 @@ private:
}
// call possible struct destructors
.destroy!(No.initialize)(*cast(T*) &this.data);
static if (is(T == struct))
{
.destroy!(No.initialize)(*cast(T*) &this.data);
}
}
}