segfault in ldc release only - looks like some kind of optimization bug?

aliak something at something.com
Tue Jul 23 00:54:08 UTC 2019


On Tuesday, 23 July 2019 at 00:36:49 UTC, Exil wrote:
> auto ref get(T)(W!T value) {
>     return value.front;
> }
>
> You're returning a reference to a temporary that gets deleted 
> at the end of the function's scope. The "auto ref" here will be 
> a "ref".

..... oh ... shit.... you're right.

Ok so this was minimized from this:

const config = Config.ghApp(ghDomain)
         .orElseThrow!(() => new Exception(
             "could not find config for domain 
'%s'".format(ghDomain)
         ));

Where Config.ghApp return an Optional!GhApp, and orElseThrow 
checks if a range has is not empty and returns front. The front 
in Optional is defined as the front above...

So is that an incorrect idiom to use when writing a library then? 
I pretty sure I've seen it in phobos too.

Slapping return on the function also fixes it. Is that the 
correct way to write a .front?

Thanks!


More information about the Digitalmars-d-learn mailing list