[Issue 890] New: Returning char[4] and assigning to char[] produces unexpected results.

d-bugmail at puremagic.com d-bugmail at puremagic.com
Fri Jan 26 01:45:54 PST 2007


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

           Summary: Returning char[4] and assigning to char[] produces
                    unexpected results.
           Product: D
           Version: 1.001
          Platform: All
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla at digitalmars.com
        ReportedBy: d at jeffmcglynn.com


import std.stdio;

char[] get_str() {
        char[4] retVal = ['t', 'e', 's', 't'];
        return retVal;
}

void main() {
        char[] res = get_str();
        writefln(res == "test" ? "SUCCESS" : "FAIL");
}


Results:

GDC 0.21 Mac, gdc -o testcase_debug -fdebug -fbounds-check unique.d
FAIL

GDC 0.21 Mac, gdc -o testcase -O3 -finline -fno-bounds-check unique.d
SUCCESS

DMD 1.002 Linux, dmd -oftestcase_debug -debug unique.d
FAIL

DMD 1.002 Linux, dmd -oftestcase -O -release -inline unique.d
SUCCESS

------

Attempting to output res results in "`_Error: 4invalid UTF-8 sequence" when
this comparison fails.  This bug also has a weird bonus:  If the comparison is
moved into a function it succeeds in debug builds, but attempting to output res
results in the above UTF-8 error.


-- 



More information about the Digitalmars-d-bugs mailing list