View mode: basic / threaded / horizontal-split · Log in · Help
February 06, 2013
[Issue 9462] New: Delegate breaks immutability
http://d.puremagic.com/issues/show_bug.cgi?id=9462

          Summary: Delegate breaks immutability
          Product: D
          Version: D2
         Platform: All
       OS/Version: All
           Status: NEW
         Keywords: accepts-invalid
         Severity: major
         Priority: P2
        Component: DMD
       AssignedTo: nobody@puremagic.com
       ReportedBy: maxim@maxim-fomin.ru


--- Comment #0 from Maxim Fomin <maxim@maxim-fomin.ru> 2013-02-06 12:39:37 PST ---
This should not work, since alternative ways of doing so (including manual
creation of delegate object and initialization of .ptr and .funcptr properties
is rejected) are banned.

import std.stdio;

struct S
{
   int i;
   void bar()
   {
       ++i;
   }
   void foo() immutable
   {
       //bar(); //error   
       (&bar)(); //works, lang hole
   }
}

void main()
{
   immutable S s;
   writeln(s.i);
   s.foo();
   writeln(s.i);
}

dmd is smart enough to avoid delegate allocation, it just issues call directly
to bar()

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
February 06, 2013
[Issue 9462] Delegate breaks immutability
http://d.puremagic.com/issues/show_bug.cgi?id=9462



--- Comment #1 from Maxim Fomin <maxim@maxim-fomin.ru> 2013-02-06 12:55:41 PST ---
Forgot to mention:  

void delegate() dg = &bar;
dg(); 

also is accepted.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Top | Discussion index | About this forum | D home