[Issue 6962] New: Wrong Code With Scope Exit + By-Ref Parameters

d-bugmail at puremagic.com d-bugmail at puremagic.com
Wed Nov 16 18:12:57 PST 2011


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: nobody at puremagic.com
        ReportedBy: dsimcha at yahoo.com
        Depends on: 6955


--- Comment #0 from David Simcha <dsimcha at 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: -------


More information about the Digitalmars-d-bugs mailing list