Comment #0 by verylonglogin.reg — 2014-03-28T05:39:45Z
This code should run fine:
---
struct S { enum a = 1; } // or `const` but not for all types
S f(ref int i)
{
++i;
return S();
}
void main()
{
int i = 2;
assert(f(i).a == 1);
assert(i == 3); // fails, i = 2
}
---
This affects infinite ranges processing e.g. `canFind(repeat(1), 2)` always returns `true` instead of infinite looping.
Comment #1 by yebblies — 2014-07-30T15:04:43Z
I guess this is valid. It works correctly when a is a static var or a static function.
Comment #2 by ag0aep6g — 2018-03-09T21:07:31Z
*** Issue 18562 has been marked as a duplicate of this issue. ***
Comment #3 by ag0aep6g — 2018-03-09T21:24:25Z
Very similar case:
----
struct S {}
S f(ref int i)
{
++i;
return S();
}
void main()
{
int i = 2;
assert(f(i) == S());
assert(i == 3); // fails, i = 2
}
----
With the enum, the struct doesn't have to be empty, but here it does.
Comment #4 by default_357-line — 2018-03-13T15:31:25Z
Posted a pull request that's awaiting review: https://github.com/dlang/dmd/pull/8013
I'm not really happy with it, but I don't know a better way to write it.
Comment #5 by github-bugzilla — 2018-04-08T18:59:15Z