Implicit conversion to mutable if no indirections?
Ali Çehreli
acehreli at yahoo.com
Fri Sep 2 18:58:43 UTC 2022
An issue I have is non-mutable expressions without indirections not
converting to mutable. I talked about this before and mentioned Unqual
at DConf 2022 to explain how it solves this.
The problem happens in template code:
void main() {
const i = 42; // const, so foo's T will be const below
foo(i);
}
void foo(T)(T value) {
T result;
++result; // Compilation error; but should it work?
}
I feel like it should work because 'result' is a local int.
But I am aware that we can't deduce T to be 'int' because we would be
losing that qualifier and further template deductions would be wrong. :/
Anyway... That's one thing that bugs me occasionally and causes bugs
like the following one, which I think is caused by a missing Unqual:
https://issues.dlang.org/show_bug.cgi?id=23319
At least, there is a moral here at least for myself: Don't forget to
test your templates with const, etc.
Ali
More information about the Digitalmars-d
mailing list