Avoid calling a qualified constructor in Cycle.#1852
Conversation
This is actually invalid code, as typeof(this) == inout(this), but Cycle has no inout constructor. This wasn't previously detected, as the constructor was mistakenly flagged as creating an unique object where qualifiers can be disregarded. (The reference parameter is leaked into the Cycle instance, so this is obviously not the case.)
|
Auto-merge toggled on |
|
thanks! |
Avoid calling a qualified constructor in Cycle.
|
I suppose that the fact that this used to compile was wrong? void main()
{
int[3] arr;
immutable c = cycle(arr);
}Because here, immutable Also, I'm wondering if the new code is actually correct. The intent was to preserve the returned type's const-ness; the new code strips it. Looking at it a bit deeper, I realize the reason it currently works is thanks (because?) of a cast I put in here. It may be better to strip that inout entirely, I introduced it something like last week. No point of keeping it if its wrong. |
|
@monarchdodra: Your example is addressed by my DMD pull request. The qualified constructor improvements would only make it easier to write a constructor that does work in the immutable case. And thanks for pointing out the bug – I guess that's what one deserves for not writing a unit test… |
This is actually invalid code, as typeof(this) == inout(this),
but Cycle has no inout constructor. This wasn't previously
detected, as the constructor was mistakenly flagged as creating
an unique object where qualifiers can be disregarded. (The
reference parameter is leaked into the Cycle instance, so
this is obviously not the case.)