www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 4416] New: Function with ref argument breaks struct method const attribute

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4416

           Summary: Function with ref argument breaks struct method const
                    attribute
           Product: D
           Version: D2
          Platform: x86
        OS/Version: Windows
            Status: NEW
          Keywords: accepts-invalid
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: bearophile_hugs eml.cc


--- Comment #0 from bearophile_hugs eml.cc 2010-07-02 05:29:05 PDT ---
This is a wrong D2 program, because bar() modifies the state of the Foo
instance, despite bar is const, but with v2.047 it compiles and runs with no
errors:


void spam(ref int x) {
    x++;
}
struct Foo {
    int x;
    void bar() const {
        spam(x);
    }
}
void main() {
    Foo b;
    assert(b.x == 0);
    b.bar();
    assert(b.x == 1);
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jul 02 2010
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4416


Andrej Mitrovic <andrej.mitrovich gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |andrej.mitrovich gmail.com


--- Comment #1 from Andrej Mitrovic <andrej.mitrovich gmail.com> 2010-08-29
19:47:59 PDT ---
This also breaks immutable class objects, which is really bad:

void spam(ref int x) 
{
    x++;
}

class Foo 
{
    int x = 5;
    void bar() immutable {
        spam(x);
    }
}
void main() 
{
    auto b = new immutable(Foo);

    //~ b.x = 10;   // uncommment for error
    assert(b.x == 5);
    b.bar();
    assert(b.x == 6);
}

If you uncomment b.x = 10, you will of course get an error. Maybe raise this
bug to a higher priority?

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Aug 29 2010
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4416



--- Comment #2 from bearophile_hugs eml.cc 2010-08-29 23:26:49 PDT ---
This is a normal bug, no need to raise its priority. There are far more urgent
bugs to fix. I have recently shown in the D newsgroup a list of my bug reports
that need higher priority. What needs higher priority are the non-additive
changes that are not just bugs.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Aug 29 2010
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4416


yebblies <yebblies gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |yebblies gmail.com
         Resolution|                            |DUPLICATE


--- Comment #3 from yebblies <yebblies gmail.com> 2011-01-26 18:27:24 PST ---
*** This issue has been marked as a duplicate of issue 5493 ***

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