[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 06:26:14 PST 2014


https://d.puremagic.com/issues/show_bug.cgi?id=12024



--- Comment #12 from monarchdodra at gmail.com 2014-01-29 06:26:10 PST ---
(In reply to comment #8)
> It should be possibly by comparing .offsetof with other members.

Smart. Unfortunatly, for a "recursive" implementation, it is a bit difficult to
exploit: More often than not, you want to know before hand that you are about
to process an aggregate in an union.

(In reply to comment #9)
> 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'
>     }
> }

Yes, absolutely. That's what I had in mind. But as I said, even detecting that
you are in an (anonymous) union is a bit difficult. Do-able with your
suggestion, just... difficult.

(In reply to comment #10)
> Interesting. So this should "just work":
> 
> diff --git a/std/algorithm.d b/std/algorithm.d
> index 036b918..0ed5606 100644
> --- a/std/algorithm.d
> +++ b/std/algorithm.d
> @@ -2054,6 +2054,9 @@ void swap(T)(ref T lhs, ref T rhs) if
> (is(typeof(lhs.proxySwap(rhs))))
>  private template allMutableFields(T)
>  {
>      alias OT = OriginalType!T;
> +    static if (is(typeof({ T t = void; t = t; })))
> +        enum allMutableFields = true;
> +    else
>      static if (is(OT == struct) || is(OT == union))
>          enum allMutableFields = isMutable!OT && allSatisfy!(.allMutableFields,
> FieldTypeTuple!OT);
>      else
> @@ -2072,6 +2075,9 @@ unittest
>      struct S2{const int i;}
>      static assert( allMutableFields!S1);
>      static assert(!allMutableFields!S2);
> +
> +    struct S3{union X{int m;const int c;}X x;}
> +    static assert( allMutableFields!S3);
>  }

I think that's wrong, because "static if (is(typeof({ T t = void; t = t; })))"
can work in the pressence of an opAssign: Complex structs with immutable
members but with a valid opAssign can't be swapped. The only case where it
would work is if T didn't have an opAssign to begin with. However, that test
would be mostly useless, since we'd have to deploy code for structs that do
have opAssign regardless.

-- 
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