Bug 8362 – std.traits.isSafe doesn't work with unsafe lamdba functions
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2012-07-08T17:41:00Z
Last change time
2012-07-27T17:44:05Z
Assigned to
nobody
Creator
iteronvexor
Comments
Comment #0 by iteronvexor — 2012-07-08T17:41:22Z
----------------------->8---------------------->8---------------------------
import std.datetime;
void ben(alias fun)() { auto b = std.datetime.benchmark!fun(1); }
struct S{ auto fun() { return 1; } }
unittest {
auto s1 = S();
ben!( {auto r = s1.fun();} )();
}
void main() { }
-----------------------8<----------------------8<---------------------------
compiling with `dmd -unittest t1.d` we get:
/home/a/Code/D/compiler/phobos/std/datetime.d(30901): Error: safe function 'benchmark' cannot call system function literal '__lambda1'
t1.d(3): Error: template instance t1.__unittest2.benchmark!(__lambda1) error instantiating
t1.d(9): instantiated from here: ben!(delegate @system void()
{
int r = s1.fun();
}
)
t1.d(9): Error: template instance t1.__unittest2.ben!(delegate @system void()
{
int r = s1.fun();
}
) error instantiating
/home/a/Code/D/compiler/phobos/std/traits.d(748): Error: safe function 'dummySafeFunc' cannot call system function literal '__lambda1'
Comment #1 by issues.dlang — 2012-07-08T18:06:13Z
Pull request https://github.com/D-Programming-Language/phobos/pull/670 happens to fix the issue with benchmark but not the underlying bug.
This code also shows it:
import std.traits;
void test(fun...)()
if(areAllSafe!fun)
{}
struct S{ auto fun() { return 1; } }
void main()
{
auto s1 = S();
static assert(!isSafe!({auto r = s1.fun();}));
}
I believe that it's a bug in std.traits.
Comment #2 by issues.dlang — 2012-07-08T18:07:14Z
Actually, I left some extra cruft in that example. The actual example is
import std.traits;
struct S{ auto fun() { return 1; } }
void main()
{
auto s1 = S();
static assert(!isSafe!({auto r = s1.fun();}));
}