Bug 6414 – Possible problem with pure and const attribute

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2011-07-30T19:45:00Z
Last change time
2011-08-27T05:14:41Z
Keywords
patch
Assigned to
nobody
Creator
bearophile_hugs

Comments

Comment #0 by bearophile_hugs — 2011-07-30T19:45:12Z
Is this a bug? class Foo { const int x; pure void bar() in { int y = x; } body {} } void main() {} DMD 2.054 gives: temp.d(5): Error: pure nested function 'bar' cannot access mutable data 'x' But x isn't even mutable.
Comment #1 by kennytm — 2011-07-30T23:53:15Z
I believe this is a rejects-valid. My pull request* to revert the unnecessarily strict purity check allows this. You could also just make `x` immutable instead of const. *: https://github.com/D-Programming-Language/dmd/pull/243
Comment #2 by bearophile_hugs — 2011-08-27T05:14:41Z
The latest versions of 2.055 give no errors, so I close this bug report.