www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 1753] New: String corruption in recursive CTFE functions

reply d-bugmail puremagic.com writes:

           Summary: String corruption in recursive CTFE functions
           Product: D
           Version: 1.024
          Platform: PC
        OS/Version: Windows
            Status: NEW
          Keywords: wrong-code
          Severity: major
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla digitalmars.com
        ReportedBy: clugdbug yahoo.com.au

In the code below, the call to bar(foo("YYY", "A")) clobbers the old value of
f, (should be "A") with the return value of the function. Halfway through the
function, the value of f changes to be "   " ! This results in silent
generation of bad code.
I encountered this in BLADE. Took a long time to track this down, even longer
to reduce it. Further simplification is probably possible, but I'm sick of it
now <g>.

char [] bar(char [] z)
    return z;

char[] foo(char [] a, char [] b) {    
        char [] f = a.length==1 ? a: foo("B", "C");
        if (a.length==1) assert(f.length==1); // OK
        char [] g = b.length==1 ? b: bar(foo("YYY", "A"));
        if (a.length==1) assert(f.length==1); // fails!
        return  "   ";

const char [] xxx = foo("A", "xxx");

Dec 29 2007
parent d-bugmail puremagic.com writes:

clugdbug yahoo.com.au changed:

           What    |Removed                     |Added
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED

------- Comment #1 from clugdbug yahoo.com.au  2008-01-02 09:15 -------
Fixed DMD 1.025

Jan 02 2008