[Issue 24637] New: [REG 2.104] Cannot insert const/immutable elements into DList
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Sat Jun 29 00:04:15 UTC 2024
https://issues.dlang.org/show_bug.cgi?id=24637
Issue ID: 24637
Summary: [REG 2.104] Cannot insert const/immutable elements
into DList
Product: D
Version: D2
Hardware: All
OS: All
Status: NEW
Severity: regression
Priority: P1
Component: dmd
Assignee: nobody at puremagic.com
Reporter: hos at hos.ac
The following code does not compile with DMD >=2.104.2:
```
import std.container : DList;
void main() {
DList!int D;
D.insert(1); // OK
int i = 2;
D.insert(i); // OK
const c = 3;
D.insert(c); // error
D.insert(c + 1); // OK
D.insert(c + c); // error
}
```
with errors:
```
/usr/include/dmd/phobos/std/algorithm/mutation.d(1469): Error: cannot modify
`const` expression `target`
/usr/include/dmd/phobos/std/algorithm/mutation.d(1265): Error: template
instance `std.algorithm.mutation.moveEmplaceImpl!(const(int))` error
instantiating
/usr/include/dmd/phobos/std/algorithm/mutation.d(1190): instantiated
from here: `moveImpl!(const(int))`
/usr/include/dmd/phobos/std/container/dlist.d(223): instantiated from
here: `move!(const(int))`
/usr/include/dmd/phobos/std/container/dlist.d(761): instantiated from
here: `createNode!(const(int))`
/usr/include/dmd/phobos/std/container/dlist.d(461): instantiated from
here: `insertBeforeNode!(const(int))`
list_const.d(12): instantiated from here: `insertBack!(const(int))`
/usr/include/dmd/phobos/std/algorithm/mutation.d(1267): Error: template
instance `std.algorithm.mutation.trustedMoveImpl!(const(int))` error
instantiating
/usr/include/dmd/phobos/std/algorithm/mutation.d(1190): instantiated
from here: `moveImpl!(const(int))`
/usr/include/dmd/phobos/std/container/dlist.d(223): instantiated from
here: `move!(const(int))`
/usr/include/dmd/phobos/std/container/dlist.d(761): instantiated from
here: `createNode!(const(int))`
/usr/include/dmd/phobos/std/container/dlist.d(461): instantiated from
here: `insertBeforeNode!(const(int))`
list_const.d(12): instantiated from here: `insertBack!(const(int))`
```
for `D.insert(c);`, or for `D.insert(c + c);` if we comment out the former.
The expected behavior is that the code compiles.
If we replace `DList` with `SList`, it compiles.
If we replace `const` with `immutable`, it gives the same error.
According to run.dlang.io, the code passes with DMD <=2.103.1.
--
More information about the Digitalmars-d-bugs
mailing list