[Issue 2482] New: Spec does not reference about special x functions in TypeInfo_Struct
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Mon Dec 1 08:55:51 PST 2008
http://d.puremagic.com/issues/show_bug.cgi?id=2482
Summary: Spec does not reference about special x functions in
TypeInfo_Struct
Product: D
Version: 2.019
Platform: PC
OS/Version: Windows
Status: NEW
Keywords: spec
Severity: normal
Priority: P2
Component: www.digitalmars.com
AssignedTo: bugzilla at digitalmars.com
ReportedBy: schveiguy at yahoo.com
The compiler treats certain operator overloads in structs in a special manner.
Specifically, if an opCmp, opEquals, toHash or toString function matches a
specific signature, a function pointer to that function is stored in the
corresponding TypeInfo_Struct for that struct.
However, if the signatures are not correct, then the function pointer is not
copied. The result is that certain builtin functions or types (or user types
which use the typeinfo to get at such functions) are not calling the
user-defined functions accessed through the TypeInfo_Struct members.
Nowhere in the spec does it mention this, or have a list of what those
signatures should be. Also, some of the spec's examples use the wrong
signature for examples of those functions. For instance, the opCmp example for
structs:
struct Pair
{
int a, b;
int opCmp(Pair rhs)
{
if (a!=rhs.a) return a-rhs.a;
return b-rhs.b;
}
}
This opCmp would *not* be used to sort an array of Pair types.
I think the spec should outline the four special functions mentioned above
(opCmp, opEquals, toHash, toString), and what specific signature they should be
for the compiler to recognize them. Also, the above example should be updated
to reflect the correct version:
struct Pair
{
int a, b;
int opCmp(const Pair *rhs) const
{
if (a!=rhs.a) return a-rhs.a;
return b-rhs.b;
}
}
--
More information about the Digitalmars-d-bugs
mailing list