On Feb 25, 2012 12:16 PM, "Caligo" <iteronve...@gmail.com> wrote: > > That was a typo, and it doesn't change anything. Here is a shorter version: > > ----------------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---------------- > > > > And here is the error: > > /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
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.