[Issue 5730] __traits(compiles) does not handle "variable has scoped destruction, cannot build closure" error correctly
via Digitalmars-d-bugs
digitalmars-d-bugs at puremagic.com
Tue Jul 7 10:08:57 PDT 2015
https://issues.dlang.org/show_bug.cgi?id=5730
Kenji Hara <k.hara.pg at gmail.com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Hardware|Other |All
OS|Linux |All
--- Comment #5 from Kenji Hara <k.hara.pg at gmail.com> ---
(In reply to Max Samukha from comment #2)
> No, no. The bug is not about the impossibility to build a closure. It is
> about __traits(compiles) not handling the compilation error properly. It
> should suppress the error and evaluate to false.
Today, a delegate literal in __traits(compiles) does not make the outer
function closure, because the delegate is just a thing only in compile time.
I'd provide better example code:
struct S
{
~this() {}
}
void main()
{
enum r = __traits(compiles, {
auto madeClosure()
{
S s;
auto dg = { auto s1 = s; };
return dg;
}
});
static assert(!r); // line 1
}
The madeClosure function will be made a closure, because the dg that refers
local variable s will escape from that. Then the "has scoped destruction..."
error needs to be captured by the __traits(compile) and r should be false.
--
More information about the Digitalmars-d-bugs
mailing list