Bug 19568 – hashOf should not unnecessarily call a struct's fields' postblits & dtors in CTFE

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
druntime
Product
D
Version
D2
Platform
All
OS
All
Creation time
2019-01-09T16:51:12Z
Last change time
2020-09-11T16:02:22Z
Assigned to
No Owner
Creator
Nathan S.

Comments

Comment #0 by n8sh.secondary — 2019-01-09T16:51:12Z
Example of code that doesn't work because a CTFE-only path in hashOf unnecessarily calls an impure destructor and tries to call a disabled postblit: --- void main() { static struct S1 { @disable this(this); ~this() @nogc nothrow { import core.stdc.stdio; if (mptr) puts("impure"); } size_t[2] pad; void* mptr; } static struct S2 { @disable this(this); ~this() @nogc nothrow { import core.stdc.stdio; if (fd != -1) puts("impure"); } int fd = -1; S1 s1; } static struct S3 { private S2 s2; } S3 s3; size_t h = ((ref S3 s3) pure => hashOf(s3))(s3); } ---
Comment #1 by n8sh.secondary — 2019-01-09T16:56:35Z
Comment #2 by n8sh.secondary — 2020-09-11T16:02:22Z
Should have auto-closed.