Thread overview | |||||
---|---|---|---|---|---|
|
November 23, 2004 foreach and inout | ||||
---|---|---|---|---|
| ||||
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 Re: foreach and inout | ||||
---|---|---|---|---|
| ||||
Posted in reply to Valéry Croizier | 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 Re: foreach and inout | ||||
---|---|---|---|---|
| ||||
Posted in reply to Sean Kelly | 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/ |
Copyright © 1999-2021 by the D Language Foundation