www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 7577] New: Delegate implicitly marked as system

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

           Summary: Delegate implicitly marked as system
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: iteronvexor gmail.com



----------------8<----------------8<----------------
import std.datetime;
import std.stdio;

struct A{

 auto fun(A a){ return 0; }
}

void bench(alias fun)(string msg, uint n = 1_000_000){

 auto b = benchmark!fun(n);
 writefln(" %s %s ms", msg, b[0].to!("msecs", int));
}

unittest{

 A a, b;

 void test1(){
   auto r = a.fun(b);
 }

 bench!( {auto r = a.fun(b);} )("Does Not work");
 bench!(test1)("Works");
}

void main(){ }
---------------->8---------------->8----------------

DMD 2.058, GNU/Linux 64-bit

/usr/include/d/dmd/phobos/std/datetime.d(30986): Error: safe function
'benchmark' cannot call system delegate '__lambda1'
t1.d(11): Error: template instance
t1.__unittest2.benchmark!(__lambda1) error instantiating
t1.d(23):        instantiated from here: bench!(delegate  system void()
{
int r = a.fun(b);
}
)
t1.d(23): Error: template instance t1.__unittest2.bench!(delegate  system
void()
{
int r = a.fun(b);
}
) error instantiating

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Feb 24 2012
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7577





 ----------------8<----------------8<----------------
 import std.datetime;
 import std.stdio;
 
 struct A{
 
  auto fun(A a){ return 0; }
 }
 
 void bench(alias fun)(string msg, uint n = 1_000_000){
 
  auto b = benchmark!fun(n);
  writefln(" %s %s ms", msg, b[0].to!("msecs", int));
 }
 
 unittest{
 
  A a, b;
 
  void test1(){
    auto r = a.fun(b);
  }
 
  bench!( {auto r = a.fun(b);} )("Does Not work");
  bench!(test1)("Works");
 }
 
 void main(){ }
 ---------------->8---------------->8----------------
 
 DMD 2.058, GNU/Linux 64-bit
 
 /usr/include/d/dmd/phobos/std/datetime.d(30986): Error: safe function
 'benchmark' cannot call system delegate '__lambda1'
 t1.d(11): Error: template instance
 t1.__unittest2.benchmark!(__lambda1) error instantiating
 t1.d(23):        instantiated from here: bench!(delegate  system void()
 {
 int r = a.fun(b);
 }
 )
 t1.d(23): Error: template instance t1.__unittest2.bench!(delegate  system
 void()
 {
 int r = a.fun(b);
 }
 ) error instantiating
A.fun is not marked as safe, so {auto r = a.fun(b);} inferred as system. Then delegate inference has no problem. Additionally, std.datetime.benchmark requires that its arguments fun are safe. I don't know why that. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Feb 25 2012
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7577


Kenji Hara <k.hara.pg gmail.com> changed:

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




 A.fun is not marked as  safe, so {auto r = a.fun(b);} inferred as  system.
 Then delegate inference has no problem.
 
 Additionally, std.datetime.benchmark requires that its arguments fun are  safe.
 I don't know why that.
Hmm, my comment was not correct, and probably a compiler bug had been there. But, it works with 2.062. Compiler bug seems already be fixed. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Feb 19 2013