www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 18232] New: string variable in toString method of Union:

https://issues.dlang.org/show_bug.cgi?id=18232

          Issue ID: 18232
           Summary: string variable in toString method of Union: invalid
                    code (crash/segfault)
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: kdevel vogtner.de

crash.d
---
import std.stdio;

union U {
   float f;
   int i;
   string toString ()
   {
      string s;
      return s;
   }
}

void main ()
{
   U u;
   writeln (u);
}
---

$ dmd crash
$ dmd
std.exception.ErrnoException /.../dmd2/linux/bin64/../../src/phobos/std/stdio.d(2776):
 (Bad address)
----------------
??:?  safe int std.exception.errnoEnforce!(int,
"/.../dmd2/linux/bin64/../../src/phobos/std/stdio.d", 2776uL).errnoEnforce(int,
lazy immutable(char)[]) [0x43f20a]
??:?  safe void
std.stdio.File.LockingTextWriter.put!(immutable(char)[]).put(immutable(char)[])
[0x4422a7]
??:?  safe void std.range.primitives.doPut!(std.stdio.File.LockingTextWriter,
immutable(char)[]).doPut(ref std.stdio.File.LockingTextWriter, ref
immutable(char)[]) [0x44224b]
??:?  safe void std.range.primitives.put!(std.stdio.File.LockingTextWriter,
immutable(char)[]).put(ref std.stdio.File.LockingTextWriter, immutable(char)[])
[0x44222b]
??:? void std.format.formatObject!(std.stdio.File.LockingTextWriter, crash.U,
char).formatObject(ref std.stdio.File.LockingTextWriter, ref crash.U, ref
const(std.format.FormatSpec!(char).FormatSpec)) [0x44220a]
??:? void std.format.formatValue!(std.stdio.File.LockingTextWriter, crash.U,
char).formatValue(ref std.stdio.File.LockingTextWriter, ref crash.U, ref
const(std.format.FormatSpec!(char).FormatSpec)) [0x44219d]
??:? uint std.format.formattedWrite!(std.stdio.File.LockingTextWriter, char,
crash.U).formattedWrite(ref std.stdio.File.LockingTextWriter, const(char[]),
crash.U) [0x43e703]
??:? void std.stdio.File.write!(crash.U, char).write(crash.U, char) [0x43e3f5]
??:? void std.stdio.writeln!(crash.U).writeln(crash.U) [0x43e389]
??:? _Dmain [0x43e344]

http://forum.dlang.org/thread/wrasraxuptrqwakrsvho forum.dlang.org

--
Jan 12