Thread overview
foreach and inout
Nov 23, 2004
Valéry Croizier
Nov 23, 2004
Sean Kelly
Nov 23, 2004
Regan Heath
November 23, 2004
Consider :

class A { int x;}
A[10] t;
foreach(A a; t) // should be "A inout a"
    a = new A;

Later, an access to any element of 't' is likely to segfault (happened to me
:).
The compiler should raise an error.


November 23, 2004
In article <co0cg2$24hq$1@digitaldaemon.com>, Valéry Croizier says...
>
>Consider :
>
>class A { int x;}
>A[10] t;
>foreach(A a; t) // should be "A inout a"
>    a = new A;
>
>Later, an access to any element of 't' is likely to segfault (happened to me
>:).
>The compiler should raise an error.

This is completely legal from a syntactical perspective--D doesn't have any concept of logical const-ness.  All you're doing is assigning a new value to a variable.


Sean


November 23, 2004
On Tue, 23 Nov 2004 22:49:06 +0000 (UTC), Sean Kelly <sean@f4.ca> wrote:

> In article <co0cg2$24hq$1@digitaldaemon.com>, Valéry Croizier says...
>>
>> Consider :
>>
>> class A { int x;}
>> A[10] t;
>> foreach(A a; t) // should be "A inout a"
>>    a = new A;
>>
>> Later, an access to any element of 't' is likely to segfault (happened to me
>> :).
>> The compiler should raise an error.
>
> This is completely legal from a syntactical perspective--D doesn't have any
> concept of logical const-ness.  All you're doing is assigning a new value to a
> variable.

Correct, if however my earlier suggestion that modifying an 'in' variable should be illegal was used this would have given an error. This is the 3rd or 4th instance where the idea would have prevented a bug.

Regan

-- 
Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/