Bug 3795 – Problem with phobos std.variant

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
Other
OS
Windows
Creation time
2010-02-11T17:50:00Z
Last change time
2014-02-14T20:35:55Z
Assigned to
andrei
Creator
bugzilla

Comments

Comment #0 by bugzilla — 2010-02-11T17:50:42Z
The problem is the unit test: const x = Variant(42); auto y = x.get!(const int)(); It relies on const int being the same type as int. It isn't, and it working before was a bug in TypeInfo's implementation. The fix is somewhere in the OpID.compare code: case OpID.compare: auto rhsP = cast(VariantN *) parm; auto rhsType = rhsP.type; // Are we the same? if (rhsType == typeid(A)) { // cool! Same type! auto rhsPA = getPtr(&rhsP.store); if (*rhsPA == *zis) { return 0; } static if (is(typeof(A.init < A.init))) { return *zis < *rhsPA ? -1 : 1; } else { // type doesn't support ordering comparisons return int.min; } } VariantN temp; // Do I convert to rhs? if (tryPutting(zis, rhsType, &temp.store)) { // cool, I do; temp's store contains my data in rhs's type! // also fix up its fptr temp.fptr = rhsP.fptr; // now lhsWithRhsType is a full-blown VariantN of rhs's type return temp.opCmp(*rhsP); } // Does rhs convert to zis? *cast(TypeInfo*) &temp.store = typeid(A); if (rhsP.fptr(OpID.get, &rhsP.store, &temp.store) == 0) { // cool! Now temp has rhs in my type! auto rhsPA = getPtr(&temp.store); if (*rhsPA == *zis) { return 0; } static if (is(typeof(A.init < A.init))) { return *zis < *rhsPA ? -1 : 1; } else { // type doesn't support ordering comparisons return int.min; } } return int.min; // dunno