[Issue 12024] [REG DMD2.065-b2] template instantiation for swap(SysTime, SysTime) fails
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Wed Jan 29 05:56:44 PST 2014
https://d.puremagic.com/issues/show_bug.cgi?id=12024
--- Comment #9 from Kenji Hara <k.hara.pg at gmail.com> 2014-01-29 05:56:38 PST ---
(In reply to comment #3)
> > Caused by https://github.com/D-Programming-Language/phobos/pull/1603
>
> Indeed. However, as I explained there, I think it is legit behavior:
>
> SysTime contains a rebindable, and Rebindable contains an immutable, and swap
> can't make the choice to mutate immutable.
>
> That said, the issue could be in Rebindable to being with: It stores an
> immutable member, but obviously mutates it all the time. In that case, why
> bother storing an immutable at all? I think the fix is there.
If a non-mutable field has one or more overlapped union _mutable_ fields, the
whole struct is treated as modifiable.
import std.traits : Unqual;
struct Rebindable(T)
{
union
{
T origin;
Unqual!T stripped; // overlapped union mutable field of 'origin'
}
}
void main()
{
Rebindable!int r1 = {origin:10};
Rebindable!int r2 = {origin:20};
r1 = r2; // Rebindable!int is modifiable (assignable)
// even if non-mutable field `T origin;` exists.
assert(r1.origin == 20);
}
If all of overlapped union fields are non-mutable, the whole struct is not also
modifiable.
struct S
{
union
{
immutable int x;
immutable int y;
}
}
void main()
{
S s1 = {x:10};
S s2 = {x:20};
s1 = s2; // cannot modify struct s1 S with immutable members
}
--
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
More information about the Digitalmars-d-bugs
mailing list