www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Why is my code does not compile? (dmd 2.021 linux)

reply Weed <resume755 mail.ru> writes:
void main()
{
     int i;

     ref int func()
     {
       return i;
     }

     func() = 4;
}

lval.d(5): found 'ref' instead of statement
lval.d(10): no identifier for declarator func
lval.d(11): unrecognized declaration


but code like this compiles:

ref int func()
{
   int* i = new int;
   return *i;
}

void main()
{
     func() = 4;
}
Dec 12 2008
parent reply "Bill Baxter" <wbaxter gmail.com> writes:
On Sat, Dec 13, 2008 at 5:45 AM, Weed <resume755 mail.ru> wrote:
 void main()
 {
    int i;

    ref int func()
    {
      return i;
    }

    func() = 4;
 }

 lval.d(5): found 'ref' instead of statement
 lval.d(10): no identifier for declarator func
 lval.d(11): unrecognized declaration


 but code like this compiles:

 ref int func()
 {
  int* i = new int;
  return *i;
 }

 void main()
 {
    func() = 4;
 }
Ref return values are a very new feature in D2. I suspect its just a bug that they don't work on inner functions yet. --bb
Dec 12 2008
parent reply Weed <resume755 mail.ru> writes:
Bill Baxter пишет:
 On Sat, Dec 13, 2008 at 5:45 AM, Weed <resume755 mail.ru> wrote:
 void main()
 {
    int i;

    ref int func()
    {
      return i;
    }

    func() = 4;
 }

 lval.d(5): found 'ref' instead of statement
 lval.d(10): no identifier for declarator func
 lval.d(11): unrecognized declaration


 but code like this compiles:

 ref int func()
 {
  int* i = new int;
  return *i;
 }

 void main()
 {
    func() = 4;
 }
Ref return values are a very new feature in D2. I suspect its just a bug that they don't work on inner functions yet. --bb
message implies that the authors are aware of this limitation? report they do not need?
Dec 12 2008
parent reply "Bill Baxter" <wbaxter gmail.com> writes:
MjAwOC8xMi8xMyBXZWVkIDxyZXN1bWU3NTVAbWFpbC5ydT46Cj4gQmlsbCBCYXh0ZXIg0MnbxdQ6
Cj4+Cj4+IE9uIFNhdCwgRGVjIDEzLCAyMDA4IGF0IDU6NDUgQU0sIFdlZWQgPHJlc3VtZTc1NUBt
YWlsLnJ1PiB3cm90ZToKPj4+Cj4+P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ICBNYW55IGhhdmUg
YmVlbiByZXBvcnRlZCwgYnV0IHRoZXJlIGFyZQpzdGlsbCBtYW55IG1vcmUgdG8gYmUgZGlzY292
ZXJlZC4gIFJldHVybmluZyByZWZzIGluIHBhcnRpY3VsYXIgaXMKdmVyeSBuZXcsIHNvIEkgd291
bGQgZXhwZWN0IGJ1Z3MgYSBwbGVudHkgd2l0aCB0aGF0LCB0aG91Z2ggSSB0aGluawpmZXcgaGF2
ZSBiZWVuIHJlcG9ydGVkIHNvIGZhci4gIEkgZG9uJ3Qga2VlcCB1cCB3aXRoIHRoZSBidWdzCm5l
d3Nncm91cCB0aGVzZSBkYXlzLCB0aG91Z2guICBDZXJ0YWlubHkgdHJ5IHRvIHNlYXJjaCBmb3Ig
aXQgaW4gdGhlCmJ1ZyBkYiBiZWZvcmUgZmlsaW5nIGEgbmV3IHJlcG9ydCwgdGhvdWdoLiAgRCdz
IGJ1Z3ppbGxhIGlzIGhlcmU6Cmh0dHA6Ly9kLnB1cmVtYWdpYy5jb20vaXNzdWVzLwoKLS1iYgo=
Dec 12 2008
parent Weed <resume755 mail.ru> writes:
Bill Baxter пишет:

 Ref return values are a very new feature in D2.  I suspect its just a
 bug that they don't work on inner functions yet.

 --bb
message implies that the authors are aware of this limitation? report they do not need?
No, a report is probably needed. There are lots of bugs with the new const and ref features in D2. Many have been reported, but there are still many more to be discovered. Returning refs in particular is very new, so I would expect bugs a plenty with that, though I think few have been reported so far. I don't keep up with the bugs newsgroup these days, though. Certainly try to search for it in the bug db before filing a new report, though. D's bugzilla is here: http://d.puremagic.com/issues/
Posted here: http://d.puremagic.com/issues/show_bug.cgi?id=2509
Dec 12 2008