Bug 6404 – Cannot check ref-ness of auto ref parameter in template constraint

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2011-07-29T22:20:00Z
Last change time
2012-02-10T06:10:29Z
Keywords
patch, rejects-valid
Assigned to
nobody
Creator
k.hara.pg

Comments

Comment #0 by k.hara.pg — 2011-07-29T22:20:45Z
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 #1 by bugzilla — 2011-07-30T13:08:23Z
Comment #2 by k.hara.pg — 2011-07-31T02:47:58Z
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 by k.hara.pg — 2011-07-31T03:21:54Z
Comment #4 by bugzilla — 2011-10-02T18:18:53Z
Comment #5 by code — 2012-02-10T06:10:29Z
I think it would be neat to extend this to IsExpressions. void foo()(auto ref int val) if (is(typeof(val) == ref))