Skip to content

Commit 539dc47

Browse files
Fix bugzilla issue 24596: std.typecons.Rebindable2: Don't destroy classes! Only destroy structs! (#9012)
1 parent aee2a7b commit 539dc47

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

std/algorithm/searching.d

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3873,6 +3873,21 @@ if (isInputRange!Range && !isInfinite!Range &&
38733873
assert([BigInt(2), BigInt(3)].maxElement == BigInt(3));
38743874
}
38753875

3876+
// https://issues.dlang.org/show_bug.cgi?id=24596
3877+
@safe unittest
3878+
{
3879+
static class A {
3880+
int i;
3881+
int getI() @safe => i;
3882+
this(int i) @safe { this.i = i; }
3883+
}
3884+
auto arr = [new A(2), new A(3)];
3885+
3886+
arr.maxElement!(a => a.getI);
3887+
3888+
assert(arr[0].getI == 2);
3889+
}
3890+
38763891
// minPos
38773892
/**
38783893
Computes a subrange of `range` starting at the first occurrence of `range`'s

std/typecons.d

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3125,7 +3125,10 @@ private:
31253125
}
31263126

31273127
// call possible struct destructors
3128-
.destroy!(No.initialize)(*cast(T*) &this.data);
3128+
static if (is(T == struct))
3129+
{
3130+
.destroy!(No.initialize)(*cast(T*) &this.data);
3131+
}
31293132
}
31303133
}
31313134

0 commit comments

Comments
 (0)