Skip to content
This repository was archived by the owner on Oct 12, 2022. It is now read-only.

Commit 335cd2e

Browse files
authored
Merge pull request #2197 from n8sh/core-hash-18920
Fix Issue 18920 - core.internal.hash of array of scalars should be `@safe` merged-on-behalf-of: Petar Kirov <ZombineDev@users.noreply.github.com>
2 parents 54ab96e + cb88e33 commit 335cd2e

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/core/internal/hash.d

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ if (!is(T == enum) && !is(T : typeof(null)) && is(T S: S[]) && !__traits(isStati
5858
//ubyteble array (arithmetic types and structs without toHash) CTFE ready for arithmetic types and structs without reference fields
5959
{
6060
auto bytes = toUbyte(val);
61-
return bytesHash(bytes.ptr, bytes.length, seed);
61+
return (() @trusted => bytesHash(bytes.ptr, bytes.length, seed))();
6262
}
6363
else //Other types. CTFE unsupported
6464
{
@@ -67,6 +67,12 @@ if (!is(T == enum) && !is(T : typeof(null)) && is(T S: S[]) && !__traits(isStati
6767
}
6868
}
6969

70+
@nogc nothrow pure @safe unittest // issue 18918
71+
{
72+
// Check hashOf dynamic array of scalars is usable in @safe code.
73+
const _ = hashOf("abc");
74+
}
75+
7076
//arithmetic type hash
7177
@trusted nothrow pure
7278
size_t hashOf(T)(auto ref T val, size_t seed = 0) if (!is(T == enum) && __traits(isArithmetic, T))

0 commit comments

Comments
 (0)