www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 6414] New: Possible problem with pure and const attribute

reply d-bugmail puremagic.com writes:
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



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: -------
Jul 30 2011
next sibling parent d-bugmail puremagic.com writes:
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



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: -------
Jul 30 2011
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=6414


bearophile_hugs eml.cc changed:

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



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: -------
Aug 27 2011