Thread overview
[Issue 5306] New: Disallow foreach ref on numeric interval
Jan 20, 2012
Walter Bright
December 02, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=5306

           Summary: Disallow foreach ref on numeric interval
           Product: D
           Version: D2
          Platform: x86
        OS/Version: Windows
            Status: NEW
          Keywords: accepts-invalid
          Severity: minor
          Priority: P2
         Component: DMD
        AssignedTo: nobody@puremagic.com
        ReportedBy: bearophile_hugs@eml.cc


--- Comment #0 from bearophile_hugs@eml.cc 2010-12-01 18:24:54 PST ---
This code compiles and runs with no errors with DMD 2.050, but I think this code is meaningless so it needs to be disallowed statically (items in the interval are not lvalues):


void main() {
    foreach (ref i; 0 .. 10) {
        i++;
    }
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
June 26, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=5306



--- Comment #1 from bearophile_hugs@eml.cc 2011-06-26 02:08:07 PDT ---
See a newer proposal bug 6214

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
January 20, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=5306


Walter Bright <bugzilla@digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |bugzilla@digitalmars.com
         Resolution|                            |INVALID


--- Comment #2 from Walter Bright <bugzilla@digitalmars.com> 2012-01-20 12:36:27 PST ---
It is not meaningless. The following program:

import core.stdc.stdio;

void main() {
    foreach (ref i; 0 .. 10) {
        printf("i = %d\n", i);
        i++;
    }
}

works as expected:

i = 0
i = 2
i = 4
i = 6
i = 8

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
January 22, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=5306



--- Comment #3 from bearophile_hugs@eml.cc 2012-01-21 19:43:09 PST ---
I don't agree much. A thread:

http://www.digitalmars.com/webnews/newsgroups.php?art_group=digitalmars.D&article_id=155816

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