diff --git a/std/algorithm/searching.d b/std/algorithm/searching.d index 2d89dea3f..42a9df518 100644 --- a/std/algorithm/searching.d +++ b/std/algorithm/searching.d @@ -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 diff --git a/std/typecons.d b/std/typecons.d index f5b48468a..3c425c7d7 100644 --- a/std/typecons.d +++ b/std/typecons.d @@ -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); + } } }