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
Comment #2 by github-bugzilla — 2018-03-30T00:46:29Z
Commits pushed to master at https://github.com/dlang/dmd https://github.com/dlang/dmd/commit/55eb8544850f4024280f1661ad0379cd9a43052b Fix Issue 18694 - pure functions using static/global structs with no fields should pass compilation https://github.com/dlang/dmd/commit/0e33d7cc27c489e8121823c1a38d5d6b2781f4c5 Merge pull request #8101 from RazvanN7/Issue_18694 Fix Issue 18694 - pure functions using static/global structs with no fields should pass compilation merged-on-behalf-of: Andrei Alexandrescu <[email protected]>