Bug 13899 – Unwanted warning for pure opApply

Status
RESOLVED
Resolution
FIXED
Severity
minor
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2014-12-27T15:57:00Z
Last change time
2015-02-18T03:41:33Z
Keywords
diagnostic, pull
Assigned to
nobody
Creator
bearophile_hugs

Comments

Comment #0 by bearophile_hugs — 2014-12-27T15:57:00Z
I think the compiler should not generate a warning in this case: const struct Foo { int opApply(immutable int delegate(in ref int) pure nothrow dg) pure nothrow { return 1; } } void main() { foreach (x; Foo()) {} } dmd 2.067alpha gives: test.d(7,5): Warning: calling test.Foo.opApply without side effects discards return value of type int, prepend a cast(void) if intentional
Comment #1 by k.hara.pg — 2014-12-28T07:01:42Z
Comment #2 by github-bugzilla — 2014-12-31T05:33:33Z
Commits pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/e57d8c052bcd1351e136cd92325c3482c1921e0b fix Issue 13899 - Unwanted warning for pure opApply Add explicit cast(void) to discard return value of opApply. https://github.com/D-Programming-Language/dmd/commit/54e6cbd6b98a61c8b048a246dec917a2d31fa569 Merge pull request #4221 from 9rnsr/fix13899 Issue 13899 - Unwanted warning for pure opApply
Comment #3 by github-bugzilla — 2015-02-18T03:41:33Z