www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 9506] New: When using alias this, writeln modifies its argument

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

           Summary: When using alias this, writeln modifies its argument
           Product: D
           Version: D2
          Platform: x86_64
        OS/Version: Mac OS X
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: olli.pottonen paivola.fi



05:39:19 PST ---
The function writeln is not expected to modify its arguments, just print them.
However when a class uses alias this, writeln clears the member variable in
question.

Example:

import std.stdio;

class test {
   uint[] _p;
   alias _p this;

   this() { _p = [1, 2]; }
}

void main()
{
    test t = new test();
    writeln(t);
    writeln(t);
}

The expected output is
[1, 2]
[1, 2]
but instead the program outputs
[1, 2]
[]

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Feb 13 2013
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9506


Andrej Mitrovic <andrej.mitrovich gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |andrej.mitrovich gmail.com



01:50:07 PST ---
This must be some kind of codegen bug, I can't recreate this on win32. I doubt
any code in writeln (or rather format) tries to do modifications like that.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Feb 14 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9506




02:10:05 PST ---

 This must be some kind of codegen bug, I can't recreate this on win32. I doubt
 any code in writeln (or rather format) tries to do modifications like that.
I suppose you're right about codegen. This bug is in v2.060 on OS X. I just tried v2.061, it works correctly. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Feb 14 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9506


yebblies <yebblies gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |yebblies gmail.com



This should be closed if it can no longer be reproduced.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jun 29 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9506




05:30:39 PDT ---
I've tested this across several compiler versions on win32:

2.058: can't compile due to template instance error
2.059: broken: [1, 2] [ ]
2.060: broken: [1, 2] [ ]
2.061: ok:     [1, 2] [1 2]
2.062: ok:     [1, 2] [1 2]
2.063: broken: [1, 2] [ ]

Even if it was fixed at some point it looks like no test-cases were added, the
bug is back.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jun 30 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9506




Gah, we missed our window.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jun 30 2013
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9506


Maxim Fomin <maxim maxim-fomin.ru> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |maxim maxim-fomin.ru
          Component|DMD                         |Phobos
         OS/Version|Mac OS X                    |All



---
Can reproduce on linux. I haven't found any codegen bug, but value
modification.

Old value = 2 //length of array
New value = 1
0x000000000043a3e6 in std.array.__T8popFrontTkZ.popFront() (a=0x7ffff7ed8ff0)
    at /usr/include/d/dmd/phobos/std/array.d:451
451        a = a[1 .. $];
(gdb) bt

    a=0x7ffff7ed8ff0) at /usr/include/d/dmd/phobos/std/array.d:451

std.format.__T11formatRangeTS3std5stdio4File17LockingTextWriterTC4main4testTaZ.formatRange()
(f=<error reading variable>, 
    val=0x7fffffffd808, w=0x7fffffffd820)
    at /usr/include/d/dmd/phobos/std/format.d:2155

std.format.__T11formatValueTS3std5stdio4File17LockingTextWriterTC4main4testTaZ.formatValue()
(f=<error reading variable>, 
    val=0x7ffff7ed8fe0, w=...) at /usr/include/d/dmd/phobos/std/format.d:2572

std.format.__T13formatGenericTS3std5stdio4File17LockingTextWriterTC4main4testTaZ.formatGeneric()
(f=<error reading variable>, 
    arg=0x7fffffffda60, w=...) at /usr/include/d/dmd/phobos/std/format.d:2996

std.format.__T14formattedWriteTS3std5stdio4File17LockingTextWriterTaTC4main4testZ.formattedWrite()
(_param_2=0x7ffff7ed8fe0, 
    fmt=..., w=...) at /usr/include/d/dmd/phobos/std/format.d:506

    this=0x695f80 <std.stdio.stdout()>, _param_1=10 '\n', 
    _param_0=0x7ffff7ed8fe0) at /usr/include/d/dmd/phobos/std/stdio.d:744

    _param_0=0x7ffff7ed8fe0) at /usr/include/d/dmd/phobos/std/stdio.d:1746


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