D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 6414 - Possible problem with pure and const attribute
Summary: Possible problem with pure and const attribute
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P2 normal
Assignee: No Owner
URL:
Keywords: patch
Depends on:
Blocks:
 
Reported: 2011-07-30 19:45 UTC by bearophile_hugs
Modified: 2011-08-27 05:14 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description bearophile_hugs 2011-07-30 19:45:12 UTC
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 kennytm 2011-07-30 23:53:15 UTC
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 bearophile_hugs 2011-08-27 05:14:41 UTC
The latest versions of 2.055 give no errors, so I close this bug report.