www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 5730] New: Error: variable has scoped destruction, cannot build closure

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5730

           Summary: Error: variable has scoped destruction, cannot build
                    closure
           Product: D
           Version: D2
          Platform: Other
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: samukha voliacable.com



PST ---
The below should compile without errors:

struct S
{
    ~this()
    {
    }
}

void main()
{
    S s;    
    enum error = __traits(compiles, { auto s1 = s; }));
    static assert(!error); // line 1
}
----
Error: static assert  (!true) is false

Comment out "line 1" to get the error that explains the problem:

Error: variable test.main.s has scoped destruction, cannot build closure

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Mar 11 2011
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5730


Walter Bright <bugzilla digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |bugzilla digitalmars.com
         Resolution|                            |INVALID



00:50:04 PST ---
Right. {auto s1=s;} is a delegate literal. Delegate literals need to be able to
survive the end of the function they are defined inside. Since s is destroyed
upon the exit from main(), then this will not work, hence the error message.

This is expected behavior, not a bug.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Mar 12 2011
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5730




PST ---
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.  

Another example:

struct S
{
    ~this()
    {
    }
}

void main()
{
    S s;    
    static if (__traits(compiles, { auto s1 = s; }))
        pragma(msg, "Can build closure");
    else
        pragma(msg, "Cannot build closure");
}
----
The compiler outputs:
Can build closure
Error: variable test.main.s has scoped destruction, cannot build closure


Instead, the above should compile successfully, printing "Cannot build closure"
at compile time.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Mar 12 2011
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5730


Max Samukha <samukha voliacable.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |REOPENED
         Resolution|INVALID                     |


-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Mar 12 2011
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5730


Max Samukha <samukha voliacable.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|Error: variable has scoped  |__traits(compiles) does not
                   |destruction, cannot build   |handle "variable has scoped
                   |closure                     |destruction, cannot build
                   |                            |closure" error correctly



PST ---
Changed the title

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Mar 12 2011
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5730


Don <clugdbug yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |clugdbug yahoo.com.au



This is happening because the "has scoped destruction" error is generated in
the glue layer, not in the front-end. The same issue applies to any error
message generated in e2ir.c, toir.c, or s2ir.c.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Mar 12 2011