D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 6404 - Cannot check ref-ness of auto ref parameter in template constraint
Summary: Cannot check ref-ness of auto ref parameter in template constraint
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P2 normal
Assignee: No Owner
URL:
Keywords: patch, rejects-valid
Depends on:
Blocks:
 
Reported: 2011-07-29 22:20 UTC by Kenji Hara
Modified: 2012-02-10 06:10 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Kenji Hara 2011-07-29 22:20:45 UTC
Cannot compile following code:

// receive only rvalue
void rvalue(T)(auto ref T x) if (!__traits(isRef, x)) {}

// receive only lvalue
void lvalue(T)(auto ref T x) if ( __traits(isRef, x)) {}

void main()
{
    int n;

    static assert(!__traits(compiles, rvalue(n)));
    static assert( __traits(compiles, rvalue(0)));

    static assert( __traits(compiles, lvalue(n)));
    static assert(!__traits(compiles, lvalue(0)));
}
Comment 2 Kenji Hara 2011-07-31 02:47:58 UTC
Sorry my patch is incomplete, because it does not support auto ref tuple parameter.

void rvalueVargs(T...)(auto ref T x) if (!__traits(isRef, x[0])) {}
void lvalueVargs(T...)(auto ref T x) if ( __traits(isRef, x[0])) {}
void test6404()
{
    int n;

    static assert(!__traits(compiles, rvalueVargs(n)));
    static assert( __traits(compiles, rvalueVargs(0)));

    static assert( __traits(compiles, lvalueVargs(n)));
    static assert(!__traits(compiles, lvalueVargs(0)));
}
Comment 3 Kenji Hara 2011-07-31 03:21:54 UTC
Retry to fix it.
https://github.com/D-Programming-Language/dmd/pull/285
Comment 5 Martin Nowak 2012-02-10 06:10:29 UTC
I think it would be neat to extend this to IsExpressions.
void foo()(auto ref int val) if (is(typeof(val) == ref))