<p>On Feb 25, 2012 12:16 PM, "Caligo" <<a href="mailto:iteronvexor@gmail.com">iteronvexor@gmail.com</a>> wrote:<br>
><br>
> That was a typo, and it doesn't change anything.  Here is a shorter version:<br>
><br>
> ----------------8<----------------8<----------------<br>
> import std.datetime;<br>
> import std.stdio;<br>
><br>
> struct A{<br>
><br>
>  auto fun(A a){ return 0; }<br>
> }<br>
><br>
> void bench(alias fun)(string msg, uint n = 1_000_000){<br>
><br>
>  auto b = benchmark!fun(n);<br>
>  writefln(" %s %s ms", msg, b[0].to!("msecs", int));<br>
> }<br>
><br>
> unittest{<br>
><br>
>  A a, b;<br>
><br>
>  void test1(){<br>
>    auto r = a.fun(b);<br>
>  }<br>
><br>
>  bench!( {auto r = a.fun(b);} )("Does Not work");<br>
>  bench!(test1)("Works");<br>
> }<br>
><br>
> void main(){ }<br>
> ---------------->8---------------->8----------------<br>
><br>
><br>
><br>
> And here is the error:<br>
><br>
> /usr/include/d/dmd/phobos/std/datetime.d(30986): Error: safe function<br>
> 'benchmark' cannot call system delegate '__lambda1'<br>
> t1.d(11): Error: template instance<br>
> t1.__unittest2.benchmark!(__lambda1) error instantiating<br>
> t1.d(23):        instantiated from here: bench!(delegate @system void()<br>
> {<br>
> int r = a.fun(b);<br>
> }<br>
> )<br>
> t1.d(23): Error: template instance t1.__unittest2.bench!(delegate @system void()<br>
> {<br>
> int r = a.fun(b);<br>
> }<br>
> ) error instantiating</p>
<p>Hmm it seems that the delegate is being implicitly marked as system, and im not sure why benchmark is @safe. I'd say file a bug report.</p>