[Issue 18694] New: pure functions using static/global structs with no fields should pass compilation
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Thu Mar 29 17:19:41 UTC 2018
https://issues.dlang.org/show_bug.cgi?id=18694
Issue ID: 18694
Summary: pure functions using static/global structs with no
fields should pass compilation
Product: D
Version: D2
Hardware: x86_64
OS: Linux
Status: NEW
Severity: enhancement
Priority: P1
Component: dmd
Assignee: nobody at puremagic.com
Reporter: andrei at erdani.com
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.
--
More information about the Digitalmars-d-bugs
mailing list