Bug 13688 – 'in' expression for AA not detected as GC usage

Status
NEW
Severity
normal
Priority
P3
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2014-11-05T11:58:48Z
Last change time
2024-12-13T18:32:47Z
Keywords
accepts-invalid
Assigned to
No Owner
Creator
sinkuupump
See also
https://issues.dlang.org/show_bug.cgi?id=19422
Moved to GitHub: dmd#18905 →

Comments

Comment #0 by sinkuupump — 2014-11-05T11:58:48Z
'in' expression for AA calls KeyType.toHash/opEquals if exist, but not detected as GC usage even if these functions are not @nogc. Example: (In this case, compiler should require that toHash/opEquals are @nogc.) struct KeyType { int x; size_t toHash() const @safe nothrow { return x; } bool opEquals(in KeyType r) const { return x == r.x; } } ulong func(ulong[KeyType] aa) @nogc { if (auto p = KeyType(10) in aa) // can call KeyType.toHash/opEquals return *p; return aa.length; }
Comment #1 by stanislav.blinov — 2021-12-08T16:51:16Z
If we go by the spec: https://dlang.org/spec/garbage.html#op_involving_gc it explicitly lists AA lookups as GC operations. That being said, AAs outright swallow attributes (see related issue). Regardless, if the specification is correct with regards to GC usage, in this case at the very least `func` shouldn't compile.
Comment #2 by robert.schadek — 2024-12-13T18:32:47Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/18905 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB