[Issue 19906] New: __traits(isRef) always yields false for auto ref parameter

d-bugmail at puremagic.com d-bugmail at puremagic.com
Mon May 27 22:00:09 UTC 2019


https://issues.dlang.org/show_bug.cgi?id=19906

          Issue ID: 19906
           Summary: __traits(isRef) always yields false for auto ref
                    parameter
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody at puremagic.com
          Reporter: andrei at erdani.com

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

--


More information about the Digitalmars-d-bugs mailing list