[Issue 20944] New: proper typedef refInt = ref int
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Wed Jun 17 21:45:44 UTC 2020
https://issues.dlang.org/show_bug.cgi?id=20944
Issue ID: 20944
Summary: proper typedef refInt = ref int
Product: D
Version: D2
Hardware: All
OS: All
Status: NEW
Severity: normal
Priority: P1
Component: dmd
Assignee: nobody at puremagic.com
Reporter: mingwu at gmail.com
https://forum.dlang.org/thread/hiolsiqiitnfddlaxuxc@forum.dlang.org
----------------
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
--
More information about the Digitalmars-d-bugs
mailing list