[Issue 18478] Spurious "escapes a reference to local variable" error in function that does not return by reference

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue Mar 20 06:57:32 UTC 2018


https://issues.dlang.org/show_bug.cgi?id=18478

--- Comment #2 from Walter Bright <bugzilla at digitalmars.com> ---
(In reply to jpdutoit from comment #0)
> In the code below, since fn2 is not returning by reference, it should not
> matter that fn1_normal and fn1_template is returning by reference.

The error is on the function returning the reference, not the function using
(or not using) the return value. Because of separate compilation, it has to be
this way.

> Some variations:
> 
> - Removing the return attribute in fn1_normal's parameter, removes "Error 1"

Right, because then the compiler thinks it isn't being returned.

> - Compiling with -dip1000 removes "Error 2".

Right, because it infers the 'return' attribute for templates.

> But then the return attribute in fn1_normal is required.

Right, because it checks the function body against the attributes.

The compiler is behaving as expected.

--


More information about the Digitalmars-d-bugs mailing list