Testcase:
```
struct A(T)
{
T _value;
bool _hasValue;
auto ref getOr(T alternativeValue)
{
return _hasValue ? _value : alternativeValue;
}
}
A!int a;
```
DMD 2.073 fails with:
> dmd -c testcase.d -o-
testcase.d(7): Error: function has 'return' but does not return any indirections
testcase.d(13): Error: template instance testcase.A!int error instantiating
DMD 2.074:
> dmd -c testcase.d -o-
testcase.d(7): Error: function type 'pure nothrow @nogc return @safe int(int alternativeValue)' has 'return' but does not return any indirections
testcase.d(13): Error: template instance manhole.A!int error instantiating
DMD 2.072.2 compiles it fine.
Comment #1 by johanengelen — 2017-06-15T22:00:31Z
Wait... is this even valid code?
It's escaping a reference to a local value.
The error message could be much improved.
Comment #2 by johanengelen — 2017-06-15T22:12:40Z
Or... it _is_ a frontend bug, as the compiler should deduce that the return type cannot be 'ref'. It correctly deduces that ("does not return any indirections") but because it added "return" function attribute earlier, the error happens.
(sorry for the confusion, not thinking clearly)
Comment #3 by dlang-bugzilla — 2017-06-18T06:45:07Z
Another error example from phobos (-dip1000, DMD64 D Compiler v2.078.2):
https://github.com/dlang/phobos/blob/master/std/range/package.d
std/range/package.d(1738) [referring to roundRobin.Result. @property auto ref front()]: Error: function type pure nothrow @nogc @property return @safe int() has return but does not return any indirections
Comment #7 by john.loughran.colvin — 2018-03-22T19:53:46Z
This seems to not to be totally resolved in very similar cases:
struct S0(T)
{
int a;
auto ref immutable(int) getA() { return a; }
}
alias A = S0!int;
test.d(4): Error: function type pure nothrow @nogc return @safe immutable(int)() has return but does not return any indirections
Comment #8 by bugzilla — 2018-03-26T03:55:54Z
(In reply to John Colvin from comment #7)
> This seems to not to be totally resolved in very similar cases:
Please do not reopen bugs because more issues come up. File a new issue instead. Otherwise, bugzilla loses the 1:1 correlation between PRs and issues, and becomes much less manageable.
I refiled it as https://issues.dlang.org/show_bug.cgi?id=18661
Closing this again.