On Monday, 12 November 2012 at 21:03:51 UTC, cal wrote:
Is the following a bug?

import std.c.string, core.memory;

void* makeNew(T)()
{
    T t = T.init;
    void* ptr = GC.malloc(T.sizeof);
    memcpy(ptr, &t, T.sizeof);
    return ptr;
}

void main()
{
    alias string T;
    T* iptr = cast(T*)makeNew!(T);
    (*iptr) = [1,2,3]; // this is allowed
}

It's not a bug.

string is an alias for immutable(char)[].
ubyte can be implicitly converted to char.
All your numbers are less than 256, so dmd is able to convert them to char.
If you try this, it fails.
string s = [256]; // 256 is > char.max

Reply via email to