| |
| Posted by d-bugmail | PermalinkReply |
|
d-bugmail
| http://d.puremagic.com/issues/show_bug.cgi?id=2078
Summary: Bizzarre array index out of bounds error with union
Product: DGCC aka GDC
Version: unspecified
Platform: Macintosh
OS/Version: Mac OS X
Status: NEW
Severity: normal
Priority: P2
Component: glue layer
AssignedTo: dvdfrdmn@users.sf.net
ReportedBy: aronnax@umd.edu
I am writing a generic vector geometry package that looks like this:
union vector(T, int N)
{
// ...
// A whole bunch of overloaded operators
// ...
T[N] data;
static if (N == 2)
{
struct { T x, y; };
}
else static if (N == 3)
{
struct { T x, y, z; };
}
else static if (N == 4)
{
struct { T w, x, y, z; };
}
string toString()
{
string s;
for (int i = 0 ; i < N - 1 ; i ++)
s += format("%.23f, ", data[i]);
s += format("%.23f", data[N]); // Line 73
return s;
}
}
typedef vector!(float, 3) vector3f;
typedef vector!(float, 4) vector4f;
typedef vector!(double, 3) vector3d;
typedef vector!(double, 4) vector4d;
And I am getting the following compile error:
vector.d:73: Error: array index 3 is out of bounds this.data[0 .. 3]
vector.d:73: Error: array index 4 is out of bounds this.data[0 .. 4]
vector.d:73: Error: array index 3 is out of bounds this.data[0 .. 3]
vector.d:73: Error: array index 4 is out of bounds this.data[0 .. 4]
See the attached source file.
Compiler is dgcc(subversion)+gcc-4.1.2 on Mac OS X 10.5.2.
--
|