[Issue 3795] New: Problem with phobos std.variant

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu Feb 11 17:50:42 PST 2010


http://d.puremagic.com/issues/show_bug.cgi?id=3795

           Summary: Problem with phobos std.variant
           Product: D
           Version: unspecified
          Platform: Other
        OS/Version: Windows
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Phobos
        AssignedTo: nobody at puremagic.com
        ReportedBy: bugzilla at digitalmars.com


--- Comment #0 from Walter Bright <bugzilla at digitalmars.com> 2010-02-11 17:50:42 PST ---
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

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list