[Issue 19904] move semantics fail through the `emplace` pipeline

d-bugmail at puremagic.com d-bugmail at puremagic.com
Mon May 27 22:07:06 UTC 2019


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

Andrei Alexandrescu <andrei at erdani.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |andrei at erdani.com

--- Comment #5 from Andrei Alexandrescu <andrei at erdani.com> ---
First, we have a problem with identifying the ref vs the non-ref instantiation.
This should compile and doesn't:

void fun(T)(auto ref T x) {
    static if (is(x == ref)) { ... }
}

This does compile, but prints the wrong thing (non ref for both cases):

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);
}

Should definitely be its own bug, so I just submitted
https://issues.dlang.org/show_bug.cgi?id=19906.

This doesn't compile:

void fun(T)(auto ref T x) {
    pragma(msg, __PRETTY_FUNCTION__);
    static if (__traits(getParameterStorageClasses, fun, 0)[0] == "ref") {
writeln("ref: ", x); }
    else { writeln("non ref: ", x); }
}

The error message suggests you can't get access to the function name from
within the function definition. This doesn't same to compile for the same
reason:

void fun(T)(auto ref T x) {
    import std.traits;
    pragma(msg, __PRETTY_FUNCTION__);
    static if (ParameterStorageClassTuple!fun[0] == ParameterStorageClass.ref_)
{ writeln("ref: ", x); }
    else { writeln("non ref: ", x); }
}

Detecting ref-ness should be easily doable from within the instantiation.
That's the first problem to tackle.

--


More information about the Digitalmars-d-bugs mailing list