[Issue 12488] foreach() should accept (and ignore) 'auto' in ForeachType
via Digitalmars-d-bugs
digitalmars-d-bugs at puremagic.com
Mon Apr 21 12:53:02 PDT 2014
https://issues.dlang.org/show_bug.cgi?id=12488
Andrej Mitrovic <andrej.mitrovich at gmail.com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |andrej.mitrovich at gmail.com
--- Comment #2 from Andrej Mitrovic <andrej.mitrovich at gmail.com> ---
I don't think this makes any sense. If we were forced to either write auto or
ref, then yeah this would actually save us from some bugs, e.g. iterating over
a struct array by value (a very common bug IMHO):
-----
struct S { int x; }
void main()
{
S[] arr;
arr.length = 2;
foreach (s; arr)
s.x = 10;
// fails
assert(arr == [S(10), S(10)]);
}
-----
In this case if we were force to use 'auto' or 'ref' then this bug would be
easier to catch.
But adding support for 'auto' without requiring a change will do us no good.
People will start questioning "why is there an auto if it doesn't do anything",
and it's always a bad idea to have two syntaxes that do the exact same thing.
It will only cause confusion.
--
More information about the Digitalmars-d-bugs
mailing list