D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 4510 - [tdpl] ref with a wrong type specifier is accepted
Summary: [tdpl] ref with a wrong type specifier is accepted
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P2 major
Assignee: No Owner
URL:
Keywords: accepts-invalid, pull, TDPL, wrong-code
Depends on:
Blocks:
 
Reported: 2010-07-26 12:02 UTC by Andrej Mitrovic
Modified: 2012-06-02 20:50 UTC (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Andrej Mitrovic 2010-07-26 12:02:01 UTC
Taken from TDPL, the following test-case shouldn't compile:

void main() {
    float[] arr = [1.0, 2.5, 4.0];
    foreach (ref double elem; arr) {
        elem /= 2;
    }
}
Comment 1 bearophile_hugs 2010-07-26 12:28:09 UTC
See also bug 3290
Comment 2 Andrej Mitrovic 2011-05-19 19:28:18 UTC
Should I add a wrong-code keyword to this?

Floats might be implicitly convertible to double, however the foreach loop doesn't actually modify the arr array.
Comment 4 github-bugzilla 2012-06-02 15:22:04 UTC
Commits pushed to master at https://github.com/D-Programming-Language/dmd

https://github.com/D-Programming-Language/dmd/commit/4591279a8c2630d03fc5a18cd326ce19ecc4dd93
fix Issue 4510 - [tdpl] ref with a wrong type specifier is accepted

https://github.com/D-Programming-Language/dmd/commit/62d6363c59362025b0c809ee865dd52d78cbf33c
Merge pull request #977 from 9rnsr/fix_foreach_arg

Issue 3290,4510,5435 - Add strict type check for foreach argument