digitalmars.D.bugs - [Issue 20944] New: proper typedef refInt = ref int
- d-bugmail puremagic.com (55/55) Jun 17 2020 https://issues.dlang.org/show_bug.cgi?id=20944
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 puremagic.com Reporter: mingwu 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 --
Jun 17 2020