[Issue 16058] New: `immutable delegate()` and `immutable delegate() immutable` are considered equal but treated differently
via Digitalmars-d-bugs
digitalmars-d-bugs at puremagic.com
Sun May 22 09:37:04 PDT 2016
https://issues.dlang.org/show_bug.cgi?id=16058
Issue ID: 16058
Summary: `immutable delegate()` and `immutable delegate()
immutable` are considered equal but treated
differently
Product: D
Version: D2
Hardware: All
OS: All
Status: NEW
Keywords: accepts-invalid
Severity: normal
Priority: P1
Component: dmd
Assignee: nobody at puremagic.com
Reporter: ag0aep6g at gmail.com
Spin-off from issue 16056.
dmd considers the two types to be equal:
----
alias A = immutable int* delegate();
alias B = immutable int* delegate() immutable;
static assert(is(A == B)); /* passes */
----
That's ok. But it treats them differently.
This is accepted with `-version=V1`, but it's rejected with `-version=V2`:
----
version (V1) alias T = immutable void delegate();
version (V2) alias T = immutable void delegate() immutable;
void main()
{
int x = 1;
T dg = { ++x; };
}
----
Both V1 and V2 should be rejected.
Furthermore, when you use both types, the first one determines how the second
is treated.
This is accepted:
----
void main()
{
int x = 1;
immutable void delegate() dg1 = { ++x; };
immutable void delegate() immutable dg2 = { ++x; };
}
----
Swap the two delegates lines and both are rejected. Again, both variants should
be rejected.
All this applies to const as well, of course.
--
More information about the Digitalmars-d-bugs
mailing list