Thread overview
[Issue 6414] New: Possible problem with pure and const attribute
Jul 31, 2011
kennytm@gmail.com
July 31, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=6414

           Summary: Possible problem with pure and const attribute
           Product: D
           Version: D2
          Platform: x86
        OS/Version: Windows
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody@puremagic.com
        ReportedBy: bearophile_hugs@eml.cc


--- Comment #0 from bearophile_hugs@eml.cc 2011-07-30 19:45:12 PDT ---
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.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
July 31, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=6414


kennytm@gmail.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |patch
                 CC|                            |kennytm@gmail.com
           Platform|x86                         |All
         OS/Version|Windows                     |All


--- Comment #1 from kennytm@gmail.com 2011-07-30 23:53:15 PDT ---
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

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
August 27, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=6414


bearophile_hugs@eml.cc changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED


--- Comment #2 from bearophile_hugs@eml.cc 2011-08-27 05:14:41 PDT ---
The latest versions of 2.055 give no errors, so I close this bug report.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------