[Issue 2521] Not possible to return immutable value by ref

2015-06-08 Thread via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=2521

Andrei Alexandrescu  changed:

   What|Removed |Added

Version|2.022   |D2

--


[Issue 2521] Not possible to return immutable value by ref

2011-06-30 Thread d-bugmail
http://d.puremagic.com/issues/show_bug.cgi?id=2521


Walter Bright  changed:

   What|Removed |Added

 Status|REOPENED|RESOLVED
 CC||bugzi...@digitalmars.com
 Resolution||FIXED


--- Comment #7 from Walter Bright  2011-06-30 
13:23:06 PDT ---
https://github.com/D-Programming-Language/dmd/commit/099ed3c987c8cca5dbb8614e21b2a5de99a49252

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
--- You are receiving this mail because: ---


[Issue 2521] Not possible to return immutable value by ref

2011-06-17 Thread d-bugmail
http://d.puremagic.com/issues/show_bug.cgi?id=2521


Kenji Hara  changed:

   What|Removed |Added

 CC||dsim...@yahoo.com


--- Comment #6 from Kenji Hara  2011-06-17 02:59:16 PDT ---
*** Issue 2780 has been marked as a duplicate of this issue. ***

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
--- You are receiving this mail because: ---


[Issue 2521] Not possible to return immutable value by ref

2011-06-07 Thread d-bugmail
http://d.puremagic.com/issues/show_bug.cgi?id=2521


yebblies  changed:

   What|Removed |Added

   Keywords||patch, rejects-valid
 CC||yebbl...@gmail.com


--- Comment #5 from yebblies  2011-06-07 04:22:52 PDT ---
This bug addresses two issues.

This does not currently work:

---

immutable int val = 23;

ref immutable(int) func()
{
return val;
}


Error: constant 23 is not an lvalue
---

And this gives the same terrible error message:

---

immutable int val = 23;

ref int func()
{
return val;
}

Error: constant 23 is not an lvalue
---

The proposed fix (dmd pull 92) allows the first case, and changes the error to
the following for the second case:

Error: cast(int)val is not an lvalue

The root cause of this bug is the fact that while running semantic on the
return expression, the immutable variable's value is known at compile time, and
is optimized without checking if the function returns an lvalue.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
--- You are receiving this mail because: ---


[Issue 2521] Not possible to return immutable value by ref

2008-12-22 Thread d-bugmail
http://d.puremagic.com/issues/show_bug.cgi?id=2521





--- Comment #4 from jason.james.ho...@gmail.com  2008-12-22 19:35 ---
This is definitely an invalid bug!

Func has a return type of "ref int".  The ref means that what gets returned by
the function can be modified (and affect the underlying data used by func).  If
the return type of func was int, I would hope the code would compile, but
that's a whole other issue...


-- 



[Issue 2521] Not possible to return immutable value by ref

2008-12-18 Thread d-bugmail
http://d.puremagic.com/issues/show_bug.cgi?id=2521





--- Comment #3 from aa...@interia.pl  2008-12-18 02:26 ---
comment to #1:
I was not sure if this was supposed to work. But please notice that it is bug
anyway as the line number in error message and message itself is totally
misleading. It suggest that problem is with variable declaration, instead of
with function.


-- 



[Issue 2521] Not possible to return immutable value by ref

2008-12-17 Thread d-bugmail
http://d.puremagic.com/issues/show_bug.cgi?id=2521


to...@yahoo.com changed:

   What|Removed |Added

 CC||to...@yahoo.com
 Status|RESOLVED|REOPENED
 Resolution|INVALID |




--- Comment #2 from to...@yahoo.com  2008-12-17 18:36 ---
>From the docs (Const and Invariant page): "Invariant declarations can appear as
lvalues, i.e. they can have their address taken, and occupy storage."

This one works:

immutable(int)* func() {
return &val;
}

I assume that this is supposed to work too:

ref immutable(int) func() {
return val;
}


-- 



[Issue 2521] Not possible to return immutable value by ref

2008-12-17 Thread d-bugmail
http://d.puremagic.com/issues/show_bug.cgi?id=2521


2kor...@gmail.com changed:

   What|Removed |Added

 Status|NEW |RESOLVED
 Resolution||INVALID




--- Comment #1 from 2kor...@gmail.com  2008-12-17 17:29 ---
Immutable variables are not lvalues, you can't take address of them because
they might not present in a final executable. For example, everywhere you use
val, it is replaced with 23. You can't return 23 by reference, can you?

Besides, returning immutable values by mutable reference is disallowed:

func() = 42; //what should this do if func() returns reference to immutable
val?


--