← Back to index
|
Original Bugzilla link
Bug 19906 – __traits(isRef) always yields false for auto ref parameter
Status
RESOLVED
Resolution
INVALID
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2019-05-27T22:00:09Z
Last change time
2019-05-28T04:43:05Z
Assigned to
No Owner
Creator
Andrei Alexandrescu
Comments
Comment #0
by andrei — 2019-05-27T22:00:09Z
Consider: import std.stdio; void fun(T)(auto ref T x) { pragma(msg, __PRETTY_FUNCTION__); static if (is(__traits(isRef, x))) { writeln("ref: ", x); } else { writeln("non ref: ", x); } } void main() { int a; fun(a); fun(42); } This prints: void onlineapp.fun!int.fun(ref int x) void onlineapp.fun!int.fun(int x) non ref: 0 non ref: 42 It should print: void onlineapp.fun!int.fun(ref int x) void onlineapp.fun!int.fun(int x) ref: 0 non ref: 42
Comment #1
by turkeyman — 2019-05-28T00:03:56Z
Oh wow... isRef is unreliable? I probably have *SO MUCH* broken code >_<
Comment #2
by sprink.noreply — 2019-05-28T00:33:26Z
The issue here is specifically with is(). __traits(isRef, x) produces the correct value and works correctly if you remove is().
Comment #3
by sprink.noreply — 2019-05-28T00:41:21Z
Just to clarify the logic would still be incorrect. It would always be true unless there was some kind of error in __traits().
Comment #4
by turkeyman — 2019-05-28T00:42:57Z
I suspect the `is` was an accident.
Comment #5
by turkeyman — 2019-05-28T00:44:11Z
Which is relieving, I was worried for a second there!
Comment #6
by andrei — 2019-05-28T04:43:05Z
Oops, my bad. Apologies.