Bug 6208 – Parameter storage classes are ignored in template function deducing.
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
Other
OS
Windows
Creation time
2011-06-24T09:00:00Z
Last change time
2012-02-11T10:15:57Z
Keywords
patch, rejects-valid
Assigned to
nobody
Creator
k.hara.pg
Comments
Comment #0 by k.hara.pg — 2011-06-24T09:00:09Z
In the following code, ref storage class of function foo's parameter s is ignored.
So calling foo with lvalue makes confusing.
----
int foo(S)(ref S s){ return 1; }
int foo(S)(S s){ return 2; }
void main()
{
int n;
assert(foo(n) == 1); // Line 6
assert(foo(0) == 2);
}
----
test.d(6): Error: template test.foo(S) foo(S) matches more than one template declaration, test.d(1):foo(S) and test.d(2):foo(S)
----
Comment #1 by k.hara.pg — 2011-06-24T09:01:35Z
P.S. Same problem exists with out and lazy.
Comment #2 by k.hara.pg — 2011-09-08T00:52:07Z
I found related issue.
Type storage classes (in, const, immutable, shared, inout) are also ignored.
void foo(T)(const T value) if (!is(T == int)) {}
void main()
{
int n;
const int cn;
static assert(!__traits(compiles, foo(n))); // OK
static assert(!__traits(compiles, foo(cn))); // NG
}