Bug 14878 – destructor of lambda parameter not included in speculative @safe check
Status
RESOLVED
Resolution
INVALID
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2015-08-06T11:25:00Z
Last change time
2015-10-04T18:20:11Z
Assigned to
nobody
Creator
code
Comments
Comment #0 by code — 2015-08-06T11:25:57Z
cat > bug.d << CODE
struct T
{
~this() @system {}
}
static assert(!__traits(compiles, (T) @safe {}));
static assert(!is(typeof((T) @safe {})));
CODE
----
This is an idiom that emerged from working on dup [¹] to quickly check whether a struct has a @safe dtor or postblit.
The postblit check `__traits(compiles, (T b) { T a = b;})` works fine.
[¹]: https://github.com/D-Programming-Language/druntime/blob/ab41e5ec1e89135b9aa9811f28f07dcf46112b82/src/object.d#L3166
Comment #1 by k.hara.pg — 2015-08-06T13:54:22Z
(In reply to Martin Nowak from comment #0)
> static assert(!__traits(compiles, (T) @safe {}));
> static assert(!is(typeof((T) @safe {})));
`(T) @safe {}` is a lambda with untyped parameter name T.
Following static asserts work as you expects.
static assert(!__traits(compiles, (T b) @safe {}));
static assert(!is(typeof((T b) @safe {})));
Comment #2 by code — 2015-08-06T22:59:48Z
(In reply to Kenji Hara from comment #1)
> Following static asserts work as you expects.
>
> static assert(!__traits(compiles, (T b) @safe {}));
> static assert(!is(typeof((T b) @safe {})));
I'm sure I tried that, but apparently not on both at the same time ;).
It didn't occur to me though that `(T) @safe {}` was parsed as polymorphic lambda with `T` being the parameter's name.
Comment #3 by github-bugzilla — 2015-08-07T09:15:19Z