[Issue 15550] New: [Reg 2.070.0-b1] compile error while testing template constraint
via Digitalmars-d-bugs
digitalmars-d-bugs at puremagic.com
Sun Jan 10 15:47:42 PST 2016
https://issues.dlang.org/show_bug.cgi?id=15550
Issue ID: 15550
Summary: [Reg 2.070.0-b1] compile error while testing template
constraint
Product: D
Version: D2
Hardware: x86_64
OS: All
Status: NEW
Severity: regression
Priority: P1
Component: dmd
Assignee: nobody at puremagic.com
Reporter: code at dawg.eu
cat > bug.d << CODE
struct Vector(T, int N)
{
void opDispatch(string, U)(U)
{
}
}
struct Matrix(T, int R, int C)
{
Matrix!(T, R, U._C) opBinary(string op, U)(U)
// this constraint causes a compile error (even though the first test
already fails)
if (is(typeof(U._isMatrix)) && (U._R == C) && (op == "*"))
{
return Matrix!(T, R, U._C)();
}
Vector!(T, R) opBinary(string op)(Vector!(T, C) x)
{
return Vector!(T, R)();
}
enum _R = R;
enum _C = C;
enum bool _isMatrix = true;
}
unittest
{
Matrix!(int, 2, 2) z;
auto z2 = z * z; // works
static assert(!is(typeof(Vector!(int, 2)._isMatrix)));
z * Vector!(int, 2)(); // errors on template constraint
}
CODE
dmd -c -unittest bug
----
math/gfm/math/matrix.d(11): Error: void has no value
math/gfm/math/matrix.d(11): Error: incompatible types for ((opDispatch!"_R") ==
(2)): 'void' and 'int'
----
There is something broken w/ the evaluation of template constraints.
if (is(typeof(U._isMatrix)) && (U._R == C) && (op == "*"))
In here the IsExp is already false, so the rest shouldn't get evaluated.
--
More information about the Digitalmars-d-bugs
mailing list