On Thursday, 13 April 2023 at 22:09:48 UTC, Jacob Shtokolov wrote:
[...]
    ref opIndex(string key) return
[...]

Regarding the return ref I found this code of 2019 on my harddisk which is from or was motivated by a dconf talk:

```
ref int foo (ref int i)
{
   return i;
}

ref int bar ()
{
   int i;
   return foo (i);
}

void main ()
{
   import std.stdio;
   auto i = bar;
   i.writeln;
}
```

Up to dmd v2.100.2 I am warned/get an error during compilation:

```
$ dmd returnref2.d
returnref2.d(3): Deprecation: returning `i` escapes a reference to parameter `i` returnref2.d(1): perhaps annotate the parameter with `return`
$ dmd -dip1000 returnref2.d
returnref2.d(3): Error: returning `i` escapes a reference to parameter `i` returnref2.d(1): perhaps annotate the parameter with `return`
```

With later dmd versions (up to including v2.102.2) the code compiles without complaints. Is this intended?
  • Returning a refe... Chris Katko via Digitalmars-d-learn
    • Re: Returni... IchorDev via Digitalmars-d-learn
    • Re: Returni... Paul Backus via Digitalmars-d-learn
    • Re: Returni... Jacob Shtokolov via Digitalmars-d-learn
      • Re: Ret... kdevel via Digitalmars-d-learn
        • Re:... Bastiaan Veelo via Digitalmars-d-learn
          • ... kdevel via Digitalmars-d-learn
            • ... Dennis via Digitalmars-d-learn
              • ... kdevel via Digitalmars-d-learn
                • ... Richard (Rikki) Andrew Cattermole via Digitalmars-d-learn
                • ... kdevel via Digitalmars-d-learn
                • ... Richard (Rikki) Andrew Cattermole via Digitalmars-d-learn
                • ... kdevel via Digitalmars-d-learn
                • ... Dennis via Digitalmars-d-learn
                • ... Dennis via Digitalmars-d-learn

Reply via email to