www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 9149] New: 'const' is broken

http://d.puremagic.com/issues/show_bug.cgi?id=9149

           Summary: 'const' is broken
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: timon.gehr gmx.ch



Delegates cannot implicitly convert to const without breaking const guarantees.
Reading a mutable delegate out of a const reference therefore must be a compile
error. (for the same reason a mutable member function cannot be called on a
const receiver.)

import std.stdio;

class T{
    int x;
    int delegate()pure b;
    this(){ b = ()pure=>x++; }
}
void main(){
    auto s=new T();
    const c = s.b; // ok, should fail
    const t=s;
    writeln(c(), c(), c(), c());
    writeln(t.b(), t.b(), t.b(), t.b()); // ok, should fail
}

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