[Issue 1417] New: templated final const member can't be assigned in constructor from the const const argument
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Sun Aug 12 22:32:05 PDT 2007
http://d.puremagic.com/issues/show_bug.cgi?id=1417
Summary: templated final const member can't be assigned in
constructor from the const const argument
Product: D
Version: 2.003
Platform: PC
OS/Version: Linux
Status: NEW
Keywords: rejects-valid
Severity: normal
Priority: P2
Component: DMD
AssignedTo: bugzilla at digitalmars.com
ReportedBy: baryluk at mpi.int.pl
----
import std.stdio;
class B(T) {
T z;
this(T _z) {
z = _z;
}
}
alias B!(int) Bi;
alias const(B!(int)) Bic;
//static assert(!(is(typeof(Bi) == typeof(Bi)))); // fails! (see #1410)
class A {
// final const(Bi) x; // works
// final const(Bic) x; // works
final const(B!(int)) x; // doesn't
// final Bic x; // also doesn't (see #1410)
this(const const(B!(int)) b) {
x = b; // Error: cannot implicitly convert expression (_x)
// of type const B to pr3.B!(int).B
// x.z = 0; // fails. good
}
const void print() {
writefln(x.z);
}
//void print2() {
//x = new const(B!(int))(6) // fails. good
//x.z = 6; // fails. good
//}
}
void main() {
const(B!(int)) b = new const(B!(int))(5);
A a = new A(b);
a.print(); // prints 5
}
----
similar problem:
----
class B(T) {
T z;
}
alias B!(int) Bi;
alias const(B!(int)) Bic;
//static assert(!(is(typeof(Bi) == typeof(Bi)))); // fails! (see #1410)
class A {
// final const(Bi) x; // works
// final const(Bic) x; // works
final const(B!(int)) x; // doesn't
// final Bic x; // also doesn't (see #1410)
// const(B!(int)) x; // works
this() {
x = new const(Bi)(); // Error: cannot implicitly convert
expression (_x)
// of type const B to pr3.B!(int).B
// x = new const(B!(int))(); // works
}
}
void main() {
A a = new A();
}
----
This bug prevents writing strictly const code with templates.
--
More information about the Digitalmars-d-bugs
mailing list