Re: union/toString: crash/segfault: What's happening here?

2018-01-12 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Jan 12, 2018 at 10:49:45AM -0800, H. S. Teoh via Digitalmars-d-learn wrote: > On Fri, Jan 12, 2018 at 11:09:47AM +, kdevel via Digitalmars-d-learn > wrote: > [...] [...] > > https://issues.dlang.org/show_bug.cgi?id=18232 > > Yep, definitely a codegen bug. Apparently, local

Re: union/toString: crash/segfault: What's happening here?

2018-01-12 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Jan 12, 2018 at 11:09:47AM +, kdevel via Digitalmars-d-learn wrote: [...] > On Friday, 12 January 2018 at 02:16:39 UTC, Adam D. Ruppe wrote: [...] > > I'd file this as a compiler codegen bug. > > https://issues.dlang.org/show_bug.cgi?id=18232 Yep, definitely a codegen bug.

Re: union/toString: crash/segfault: What's happening here?

2018-01-12 Thread kdevel via Digitalmars-d-learn
Thanks for the quick answer! On Friday, 12 January 2018 at 02:16:39 UTC, Adam D. Ruppe wrote: On Friday, 12 January 2018 at 00:54:03 UTC, kdevel wrote: $ dmd crash.d $ ./crash Nicholas Wilson is right that you can use = "" to work around it, but with strings, null is supposed to behave the

Re: union/toString: crash/segfault: What's happening here?

2018-01-11 Thread Adam D. Ruppe via Digitalmars-d-learn
On Friday, 12 January 2018 at 00:54:03 UTC, kdevel wrote: $ dmd crash.d $ ./crash Nicholas Wilson is right that you can use = "" to work around it, but with strings, null is supposed to behave the same way. And this gives different (each wrong) behavior on -m32 vs -m64, which leads me to

Re: union/toString: crash/segfault: What's happening here?

2018-01-11 Thread ag0aep6g via Digitalmars-d-learn
On 01/12/2018 02:45 AM, Nicholas Wilson wrote: because you don't initialise `s` in    string toString ()    {   string s;   return s;    } so it defaults to `string s = null;` thus giving a segfault. try `string s = "";` instead. A null string is a perfectly fine empty string.

Re: union/toString: crash/segfault: What's happening here?

2018-01-11 Thread Adam D. Ruppe via Digitalmars-d-learn
On Friday, 12 January 2018 at 01:45:37 UTC, Nicholas Wilson wrote: so it defaults to `string s = null;` thus giving a segfault. null and "" are basically the same for strings. that's not the problem.

Re: union/toString: crash/segfault: What's happening here?

2018-01-11 Thread Nicholas Wilson via Digitalmars-d-learn
On Friday, 12 January 2018 at 00:54:03 UTC, kdevel wrote: 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.d $ ./crash because you don't initialise `s` in

union/toString: crash/segfault: What's happening here?

2018-01-11 Thread kdevel via Digitalmars-d-learn
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.d $ ./crash std.exception.ErrnoException@/.../dmd2/linux/bin64/../../src/phobos/std/stdio.d(2776): (Bad