www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 15708] New: std.range.choose assumes

https://issues.dlang.org/show_bug.cgi?id=15708

          Issue ID: 15708
           Summary: std.range.choose assumes hasElaborateCopyConstructor
                    means "has __postblit"
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P1
         Component: phobos
          Assignee: nobody puremagic.com
          Reporter: acehreli yahoo.com

The following program fails compilation:

import std.stdio : stdin;
import std.range: choose;

void main()
{
    ubyte[1][] secondRange;
    choose(true, stdin.byChunk(1), secondRange);
}

/usr/include/dmd/phobos/std/range/package.d(1296): Error: no property
'__postblit' for type 'ByChunk', did you mean '__xpostblit'?

Forum thread:

  http://forum.dlang.org/thread/ylcpaldlbbsmbceeoxou forum.dlang.org

The reason is, std.range.choose has the following post-blit:

        static if (hasElaborateCopyConstructor!R1
            || hasElaborateCopyConstructor!R2)
        this(this)
        {
            if (condition)
            {
                static if (hasElaborateCopyConstructor!R1) r1.__postblit();
            }
            else
            {
                static if (hasElaborateCopyConstructor!R2) r2.__postblit();
            }
        }

However, hasElaborateCopyConstructor may be true even if there is no
__postblit:

template hasElaborateCopyConstructor(S)
{
    static if(isStaticArray!S && S.length)
    {
        enum bool hasElaborateCopyConstructor =
hasElaborateCopyConstructor!(typeof(S.init[0]));
    }
    else static if(is(S == struct))
    {
        enum hasElaborateCopyConstructor = hasMember!(S, "__postblit")
            || anySatisfy!(.hasElaborateCopyConstructor, FieldTypeTuple!S);
    }
    else
    {
        enum bool hasElaborateCopyConstructor = false;
    }
}

Ali

--
Feb 20 2016