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

d-bugmail at puremagic.com d-bugmail at puremagic.com
Fri Jun 15 19:38:21 PDT 2012


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


Kenji Hara <k.hara.pg at gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |wrong-code


--- Comment #10 from Kenji Hara <k.hara.pg at gmail.com> 2012-06-15 19:40:31 PDT ---
(In reply to comment #9)
> (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.

They are the phases to change behavior. I think we should allow modifying loop
variable in foreach body, but it should not affect to iteration.

> 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.

#3 is a goal.

> 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.

http://d.puremagic.com/test-results/pulls.ghtml
See auto tester. With all pull request, Phobos compile succeeds. So there is no
code that changes the foreach-on-range iteration variable.

-- 
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