const->immutable array argument?

Steven Schveighoffer schveiguy at yahoo.com
Tue Sep 20 05:37:32 PDT 2011


On Tue, 20 Sep 2011 07:33:20 -0400, bearophile <bearophileHUGS at lycos.com>  
wrote:

> In this bug report I have asked for better error messages:
> http://d.puremagic.com/issues/show_bug.cgi?id=6696
>
> But beside the error message, do you know why an immutable ref can't be  
> given to a function with a const ref argument? foo() can't change the  
> contents of the array a any way, so what's wrong in this code?
>
>
> void foo(const ref int[5] a) {}
> void main() {
>     immutable int[5] arr;
>     foo(arr); // Error?
> }


BTW, when posting questions like this, it is *immensely* helpful to give  
exact error messages, so I don't have to try it out to see what you are  
talking about.  I spent a while writing a response until I saw the error  
message (which changed completely how I viewed the issue), and erased it  
before writing my eventual reply.

-Steve


More information about the Digitalmars-d-learn mailing list