This repository was archived by the owner on Oct 12, 2022. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +19
-2
lines changed Expand file tree Collapse file tree 1 file changed +19
-2
lines changed Original file line number Diff line number Diff line change @@ -139,10 +139,11 @@ size_t hashOf(T)(auto ref T val, size_t seed = 0) if (!is(T == enum) && (is(T ==
139
139
{
140
140
return bytesHash (toUbyte(val), seed);
141
141
}
142
- else // CTFE unsupproreted for structs with reference fields
142
+ else // CTFE unsupported
143
143
{
144
144
assert (! __ctfe, " unable to compute hash of " ~ T.stringof);
145
- return bytesHash (toUbyte(val), seed);
145
+ const (ubyte )[] bytes = (() @trusted => (cast (const (ubyte )* )&val)[0 .. T.sizeof])();
146
+ return bytesHash (bytes, seed);
146
147
}
147
148
}
148
149
}
@@ -154,6 +155,22 @@ nothrow pure @safe unittest // issue 18925
154
155
auto h = hashOf(S.init);
155
156
}
156
157
158
+ nothrow pure @safe unittest // issue 19005
159
+ {
160
+ enum Month : ubyte
161
+ {
162
+ jan = 1
163
+ }
164
+ static struct Date
165
+ {
166
+ short _year;
167
+ Month _month;
168
+ ubyte _day;
169
+ }
170
+ Date date;
171
+ auto hash = date.hashOf;
172
+ }
173
+
157
174
// delegate hash. CTFE unsupported
158
175
@trusted nothrow pure
159
176
size_t hashOf (T)(auto ref T val, size_t seed = 0 ) if (! is (T == enum ) && is (T == delegate ))
You can’t perform that action at this time.
0 commit comments