Re: const ref void[] – float[] not implicitly convertable to void[]

Jonathan M Davis jmdavisProg at gmx.com
Mon Jul 23 14:02:05 PDT 2012


On Monday, July 23, 2012 12:04:09 David wrote:
> Is this a bug? – http://dpaste.dzfl.pl/31a16eab (code below)
> 
> 
> ------------
> void test(const void* test, size_t length) {
> }
> 
> void foo_const_ref(const ref void[] data) {
> test(data.ptr, data.length);
> }
> 
> void foo_ref(ref void[] data) {
> test(data.ptr, data.length);
> }
> 
> void foo(void[] data) {
> test(data.ptr, data.length);
> }
> 
> 
> void main() {
> float[] bar = [1.0f, 1.0f, 1.0f, 1.0f, 1.0f];
> void[] v_bar = bar;
> 
> foo(bar);
> foo_ref(bar);
> foo_const_ref(bar);
> 
> foo(v_bar);
> foo_ref(v_bar);
> foo_const_ref(v_bar);
> }
> ------------
> 519.d(22): Error: function compileme519.foo_ref (ref void[] data) is not
> callable using argument types (float[])

> 519.d(22): Error: cast(void[])bar is not an lvalue
> 519.d(23): Error: function compileme519.foo_const_ref (ref const(void[])
> data) is not callable using argument types (float[])
> 519.d(23): Error: cast(const(void[]))bar is not an lvalue
> ------------
> 
> Seems like float[] isn't convertable to void[] anylonger.

Of course that doesn't work. ref must refer to an lvalue, so it can't convert 
anything. The type must match exactly save for constness. So float[] can't be 
passed to a function taking ref void[]. Either you need to convert to assign 
the float[] to a void[] variable first, or you need the function to take ref 
float[].

- Jonathan M Davis


More information about the Digitalmars-d-learn mailing list