[Issue 7577] Delegate implicitly marked as system

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sat Feb 25 21:24:03 PST 2012


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



--- Comment #1 from Kenji Hara <k.hara.pg at gmail.com> 2012-02-25 21:24:01 PST ---
(In reply to comment #0)
> ----------------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: -------


More information about the Digitalmars-d-bugs mailing list