www.digitalmars.com         C & C++   DMDScript  

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


          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)
            if (condition)
                static if (hasElaborateCopyConstructor!R1) r1.__postblit();
                static if (hasElaborateCopyConstructor!R2) r2.__postblit();

However, hasElaborateCopyConstructor may be true even if there is no

template hasElaborateCopyConstructor(S)
    static if(isStaticArray!S && S.length)
        enum bool hasElaborateCopyConstructor =
    else static if(is(S == struct))
        enum hasElaborateCopyConstructor = hasMember!(S, "__postblit")
            || anySatisfy!(.hasElaborateCopyConstructor, FieldTypeTuple!S);
        enum bool hasElaborateCopyConstructor = false;


Feb 20 2016