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

2018-03-22 Thread d-bugmail--- via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=18478

Carsten Blüggel  changed:

   What|Removed |Added

 Blocks|18444   |


Referenced Issues:

https://issues.dlang.org/show_bug.cgi?id=18444
[Issue 18444] [DIP25][DIP1000] Tracking issue for: "The implementation doesn't
match DIPs 25/1000"
--


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

2018-03-20 Thread d-bugmail--- via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=18478

--- Comment #5 from Carsten Blüggel  ---
(In reply to Walter Bright from comment #3)
> (In reply to Carsten Blüggel from comment #1)
> > Another error example from phobos that appeared in master within the last
> > ~24h:
> 
> I don't really understand what you mean. In any case, it does not seem to be
> the same thing as in the first comment. Please clarify and file as a
> separate bugzilla issue.

I hope, that I expressed my concern better in new separate
https://issues.dlang.org/show_bug.cgi?id=18637

--


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

2018-03-20 Thread d-bugmail--- via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=18478

--- Comment #4 from jpdut...@gmail.com ---

(In reply to Walter Bright from comment #2)
> 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.

I assume you are speaking about fn2.

Storing the result to a temporary before returning removes the error:

auto tmp = fn1_normal(a);
return tmp;

I would expect the compiler to implicitly decay the returned reference to a
normal value when it sees that fn2 does not return by reference, the same way
it is done when first saving it into a temporary.

In any case, the error "returning fn1_normal(a) escapes a reference to local
variable a" does not describe what is actually going on, because no reference
would actually escape even if this error was disabled.

--


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

2018-03-20 Thread d-bugmail--- via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=18478

Walter Bright  changed:

   What|Removed |Added

 Status|NEW |RESOLVED
 Resolution|--- |INVALID

--- Comment #3 from Walter Bright  ---
(In reply to Carsten Blüggel from comment #1)
> Another error example from phobos that appeared in master within the last
> ~24h:

I don't really understand what you mean. In any case, it does not seem to be
the same thing as in the first comment. Please clarify and file as a separate
bugzilla issue.

--


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

2018-03-20 Thread d-bugmail--- via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=18478

--- Comment #2 from Walter Bright  ---
(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.

--


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

2018-03-16 Thread d-bugmail--- via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=18478

Carsten Blüggel  changed:

   What|Removed |Added

   Keywords||rejects-valid, spec

--- Comment #1 from Carsten Blüggel  ---
Another error example from phobos that appeared in master within the last ~24h:
https://github.com/dlang/phobos/blob/master/std/exception.d

make -f posix.mak std/exception.test (-dip1000 for that module; DMD64 master)

std/exception.d(1243): Error: returning & i escapes a reference to local
variable i

excerpt from std/exception.d:

/// Arrays (dynamic and static)
@system unittest
{
int i;
int[]  slice = [0, 1, 2, 3, 4];
int[5] arr   = [0, 1, 2, 3, 4];
int*[]  slicep = [];   <= line 1243
int*[1] arrp   = [];
...
assert( slicep[0].doesPointTo(i));   <= slicep usage
assert(!slicep   .doesPointTo(i));   <= slicep usage
...

1. This is @system code, allowed to escape whatever
2. There is no escape (commenting out slicep usages doesn't change error
reported)

--


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

2018-03-16 Thread d-bugmail--- via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=18478

Carsten Blüggel  changed:

   What|Removed |Added

 Blocks||18444


Referenced Issues:

https://issues.dlang.org/show_bug.cgi?id=18444
[Issue 18444] [DIP25][DIP1000] Tracking issue for: "The implementation doesn't
match DIPs 25/1000"
--


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

2018-03-15 Thread d-bugmail--- via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=18478

Carsten Blüggel  changed:

   What|Removed |Added

 CC||chi...@posteo.net

--


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

2018-03-03 Thread d-bugmail--- via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=18478

Walter Bright  changed:

   What|Removed |Added

   Keywords||safe
 CC||bugzi...@digitalmars.com

--