http://d.puremagic.com/issues/show_bug.cgi?id=6962

           Summary: Wrong Code With Scope Exit + By-Ref Parameters
           Product: D
           Version: D2
          Platform: Other
        OS/Version: Windows
            Status: NEW
          Keywords: wrong-code
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nob...@puremagic.com
        ReportedBy: dsim...@yahoo.com
        Depends on: 6955


--- Comment #0 from David Simcha <dsim...@yahoo.com> 2011-11-16 18:12:10 PST ---
The following code was reduced from std.conv.  It prints "BAD!!!" only with -O
enabled.  Since parse() gets rid of the entire contents of v, v.length should
be zero upon exiting toImpl and nothing should be printed.

import core.stdc.stdio;

T toImpl(T)(immutable string value)
{
    string v = value;  

    scope(exit)
    {
        if (v.length)
        {
            printf("BAD!!!");
        }
    }
    return parse!T(v);
}

T parse(T)(ref string value) 
{
    value = value[0..0];
    return 666;
}

void main() 
{
    immutable s = "42";
    toImpl!float(s);
}

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

Reply via email to