www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 3795] New: Problem with phobos std.variant

reply d-bugmail puremagic.com writes:
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 puremagic.com
        ReportedBy: bugzilla digitalmars.com


--- Comment #0 from Walter Bright <bugzilla 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: -------
Feb 11 2010
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3795


Andrei Alexandrescu <andrei metalanguage.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |ASSIGNED
                 CC|                            |andrei metalanguage.com
         AssignedTo|nobody puremagic.com        |andrei metalanguage.com


-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Feb 11 2010
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3795


Andrei Alexandrescu <andrei erdani.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|                            |FIXED


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