Bug 18694 – pure functions using static/global structs with no fields should pass compilation
Status
RESOLVED
Resolution
FIXED
Severity
enhancement
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2018-03-29T17:19:41Z
Last change time
2018-03-30T00:46:30Z
Assigned to
No Owner
Creator
Andrei Alexandrescu
Comments
Comment #0 by andrei — 2018-03-29T17:19:41Z
Consider:
struct S { enum int x = 42; }
static S dummy;
pure int fun(int x)
{
return dummy.x + x;
}
This code fails to compile:
Error: pure function onlineapp.fun cannot access mutable static data dummy
However, there is no mutable data to talk about in the first place so the code should pass compilation.
The technique of using static data for a zero-sized struct is frequently used in the allocator framework.
Comment #1 by razvan.nitu1305 — 2018-03-29T18:00:14Z