import std.conv;
import std.math;
void main()
{
import std.stdio;
vec3 w = vec3();
writefln("%f w: %f", 3.5f, w.length);
}
struct Vector(T, int dim)
{
union
{
struct
{
T x = 0;
T y = 0;
T z = 0;
}
T[dim] cell;
}
string toString() {
return to!string(cell);
}
/// return length*length
@property T sqLength()
{
return cast()x * x + y * y + z * z;
}
/// return the vector length
@property T length() {
toString;
auto ret = sqLength;
return sqrt(ret);
}
}
alias Vector!(float, 3) vec3;
$ dmd -debug -gc vector.d && gdb --batch -ex 'run' -ex 'bt 15' ./vector
Program received signal SIGSEGV, Segmentation fault.
0x00007ffff7669faa in snprintf () from /lib/x86_64-linux-gnu/libc.so.6
#0 0x00007ffff7669faa in snprintf () from /lib/x86_64-linux-gnu/libc.so.6
#1 0x000000000044affe in void std.format.formatValue!(std.array.Appender!(immutable(char)[]).Appender, float, char).formatValue(std.array.Appender!(immutable(char)[]).Appender, float, ref std.format.FormatSpec!(char).FormatSpec) (f=0x7fffffffdcd8, obj=0, w=...) at /home/trass3r/coding/dmd/linux/bin64/../../src/phobos/std/format.d:1204
#2 0x000000000044b387 in void std.format.formatElement!(std.array.Appender!(immutable(char)[]).Appender, float, char).formatElement(std.array.Appender!(immutable(char)[]).Appender, float, ref std.format.FormatSpec!(char).FormatSpec) (f=0x7fffffffdcd8, val=0, w=...) at /home/trass3r/coding/dmd/linux/bin64/../../src/phobos/std/format.d:1596
#3 0x000000000044a661 in void std.format.formatRange!(std.array.Appender!(immutable(char)[]).Appender, float[], char).formatRange(std.array.Appender!(immutable(char)[]).Appender, float[], ref std.format.FormatSpec!(char).FormatSpec) (f=0x7fffffffdcd8, val=0x00007fffffffdd780000000000000003, w=...) at /home/trass3r/coding/dmd/linux/bin64/../../src/phobos/std/format.d:1452
#4 0x000000000044a50f in void std.format.formatValue!(std.array.Appender!(immutable(char)[]).Appender, float[], char).formatValue(std.array.Appender!(immutable(char)[]).Appender, float[], ref std.format.FormatSpec!(char).FormatSpec) (f=0x7fffffffdcd8, val=0x00007fffffffdd780000000000000003, w=...) at /home/trass3r/coding/dmd/linux/bin64/../../src/phobos/std/format.d:1386
#5 0x000000000044a4dd in immutable(char)[] std.conv.toStr!(immutable(char)[], float[]).toStr(float[]) (src=0x00007fffffffdd780000000000000003) at /home/trass3r/coding/dmd/linux/bin64/../../src/phobos/std/conv.d:94
#6 0x000000000044a48f in immutable(char)[] std.conv.toImpl!(immutable(char)[], float[]).toImpl(float[]) (s=0x00007fffffffdd780000000000000003) at /home/trass3r/coding/dmd/linux/bin64/../../src/phobos/std/conv.d:803
#7 0x000000000044a401 in immutable(char)[] std.conv.toImpl!(immutable(char)[], float[3]).toImpl(ref float[3]) (s=0x7fffffffdd78) at /home/trass3r/coding/dmd/linux/bin64/../../src/phobos/std/conv.d:353
#8 0x000000000044a381 in immutable(char)[] std.conv.to!(immutable(char)[]).to!(float[3]).to(float[3]) (_param_0=...) at /home/trass3r/coding/dmd/linux/bin64/../../src/phobos/std/conv.d:237
#9 0x0000000000442d3f in immutable(char)[] vector.Vector!(float, 3).Vector.toString() (this=0x7fffffffde10) at vector.d:25
#10 0x0000000000442df6 in @property float vector.Vector!(float, 3).Vector.length() (this=0x7fffffffde10) at vector.d:36
Comment #1 by hsteoh — 2013-08-18T22:09:06Z
I can't reproduce this bug in git HEAD (1a6da16ef112e03607574758b722698f2950b0de) running on Linux/64. Could you check to see if it still occurs either in the latest release or in git HEAD? Since it's been a while, the bug may have been fixed already.
Comment #2 by hsteoh — 2013-08-20T12:45:26Z
It's probably a good idea to add this code to a unittest in std.conv, to prevent regressions in the future.