www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 9133] New: std.datetime: Cannot implicitly convert const(SysTime) to SysTime

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9133

           Summary: std.datetime: Cannot implicitly convert const(SysTime)
                    to SysTime
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Phobos
        AssignedTo: nobody puremagic.com
        ReportedBy: bugzilla kyllingen.net



01:38:37 PST ---
Test case:

    import std.datetime;
    const SysTime a;
    SysTime b = a;

Error: cannot implicitly convert expression (a) of type const(SysTime) to
SysTime

This is extremely surprising to me, as I would expect SysTime to have value
semantics.  I suppose this has to do with the timezone field?

If this problem is unavoidable, I think that SysTime should either have a
copy/dup method, or at the very least it should be noted in the documentation
whether it is safe to cast it to mutable.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Dec 10 2012
parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9133


Jonathan M Davis <jmdavisProg gmx.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jmdavisProg gmx.com
          Component|Phobos                      |DMD



PST ---
It's an issue with dmd. For whatever reason, it won't let you assign a SysTime
to const or immutable even though everything in it should be convertible to
const. The fact that it contains reference to a class screws it up, even though
it's immutable. You have to have a postblit to fix it, but you can't have a
const or immutable postblit, so you can't copy it if it's const or immutable.
This problem occurs with every single struct which has reference types in it
aside from dynamic arrays. It's something that needs to be solved in the
language and the compiler. So, it comes down to two things:

1. dmd should be smart enough to realize that it doesn't need a postblit
constructor in this case (because the class is immutable), but it isn't.

2. postblit is inherently broken with regards to const and immutable. This is a
huge problem that goes way beyond just std.datetime.

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