[Issue 6652] foreach parameter with number range is always ref

d-bugmail at puremagic.com d-bugmail at puremagic.com
Fri Jun 15 11:54:23 PDT 2012


http://d.puremagic.com/issues/show_bug.cgi?id=6652



--- Comment #9 from bearophile_hugs at eml.cc 2012-06-15 11:56:35 PDT ---
(In reply to comment #8)

> To reduce breaking of existing codes,
> 1. Warn to modifying loop variable in foreach body.
>    It is shown only when -w switch is specified.
> 2. Deprecate modifying loop variable in foreach body.
>    If user specifies -d switch, it is allowed.
> 3. Allow modifying loop variable in foreach body, and it does not affect to
>    the number of iterations of the loop.

This is great, you are the best Kenji Hara.

I prefer the number 2. I think it breaks none of my programs.

The number 3 is a trap, because it silently changes the semantics of old D
code. And it's bug-prone for new D programmers too because they can change the
variable by mistake. Generally immutable variables are safer.


Are you able and willing to compile the whole Phobos with the option number 2?
So we can see how often Phobos code change the foreach-on-range iteration
variable.


What's the semantics of this, now?
foreach (ref int i; 0 .. 10) i++;

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list