[Issue 11929] New: Disallow `ref` in front tuple expansion in foreach over range

d-bugmail at puremagic.com d-bugmail at puremagic.com
Wed Jan 15 00:46:36 PST 2014


https://d.puremagic.com/issues/show_bug.cgi?id=11929

           Summary: Disallow `ref` in front tuple expansion in foreach
                    over range
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Keywords: accepts-invalid
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody at puremagic.com
        ReportedBy: verylonglogin.reg at gmail.com


--- Comment #0 from Denis Shelomovskij <verylonglogin.reg at gmail.com> 2014-01-15 12:46:34 MSK ---
As currently `ref` is allowed in front tuple expansion such dangerous code is
accepted and fails only in runtime:
---
import std.range;

void main()
{
    int[] arr = new int[1];
    foreach(ref a, b; zip(arr, new int[1]))
        ++a;
    assert(arr[0] == 1);
}
---

IMO such code should reject to compile as I see no general use for access to
tuple element by `ref`. Broken after such change code most likely is invalid.

Also front tuple expansion in foreach over range isn't documented. See Issue
7361.

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


More information about the Digitalmars-d-bugs mailing list