https://forum.dlang.org/thread/[email protected]
----------------
import std.stdio;
alias refInt = ref int;
void f(refInt i) {
i = 456;
}
void main() {
int i = 123;
writeln(i);
f(i);
writeln(i);
}
----------------
$ $DMD/windows/bin64/rdmd.exe reft.d
123
123
$ $LDC/bin/rdmd reft.d
123
123
I would consider it a bug, *even* C++ can handle this better :-) i.e. no surprise to the programmer.
cat reft.cpp
----------------------
#include <stdio.h>
typedef int& refInt;
void f(refInt i) {
i = 456;
}
int main() {
int i = 123;
printf("%d\n", i);
f(i);
printf("%d\n", i);
}
----------------------
$ make reft
g++ reft.cpp -o reft
$ ./reft
123
456
Comment #1 by stanislav.blinov — 2020-06-17T22:02:29Z
This is not a bug. ref is a storage class for parameters and return values, and not part of a type. There is no surprise here, at all.
Comment #2 by moonlightsentinel — 2020-06-17T22:24:18Z
The only bug here is that `ref` isn't properly rejected.
Comment #3 by stanislav.blinov — 2020-06-17T23:03:47Z