https://issues.dlang.org/show_bug.cgi?id=5730

Kenji Hara <[email protected]> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Hardware|Other                       |All
                 OS|Linux                       |All

--- Comment #5 from Kenji Hara <[email protected]> ---
(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.

--

Reply via email to