digitalmars.D.learn - passing struct literals by reference (dmd 2.060, Windows)
- Jack Applegame (12/12) Nov 24 2012 struct Foo {
- Jonathan M Davis (7/20) Nov 24 2012 It should be illegal, but in C++, struct literals are lvalues for some r...
- Jonathan M Davis (3/30) Nov 24 2012 http://d.puremagic.com/issues/show_bug.cgi?id=9069
struct Foo { int a; } void modify(ref Foo foo) { foo.a++; } void main() { modify(Foo(1)); } Why compiler doesn't report error? So as struct literal "Foo()" isn't a lvalue, it's impossible to pass it by reference. Isn't it? Just like string or numeric literals.
Nov 24 2012
On Saturday, November 24, 2012 10:59:24 Jack Applegame wrote:struct Foo { int a; } void modify(ref Foo foo) { foo.a++; } void main() { modify(Foo(1)); } Why compiler doesn't report error? So as struct literal "Foo()" isn't a lvalue, it's impossible to pass it by reference. Isn't it? Just like string or numeric literals.It should be illegal, but in C++, struct literals are lvalues for some reason, and D inherited that stupidity (it's just less noticeable in C++, because of how C++ handles const&). We managed to get Walter to change it temporarily, but he seems to have changed it back. I thought that I'd reported it, but I don't see a bug report for it now. I'll have to go create one. - Jonathan M Davis
Nov 24 2012
On Saturday, November 24, 2012 02:11:23 Jonathan M Davis wrote:On Saturday, November 24, 2012 10:59:24 Jack Applegame wrote:http://d.puremagic.com/issues/show_bug.cgi?id=9069 - Jonathan M Davisstruct Foo { int a; } void modify(ref Foo foo) { foo.a++; } void main() { modify(Foo(1)); } Why compiler doesn't report error? So as struct literal "Foo()" isn't a lvalue, it's impossible to pass it by reference. Isn't it? Just like string or numeric literals.It should be illegal, but in C++, struct literals are lvalues for some reason, and D inherited that stupidity (it's just less noticeable in C++, because of how C++ handles const&). We managed to get Walter to change it temporarily, but he seems to have changed it back. I thought that I'd reported it, but I don't see a bug report for it now. I'll have to go create one.
Nov 24 2012