[Issue 23657] New: [REG2.101] Incorrect error escape reference to stack allocated value
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Thu Jan 26 23:14:12 UTC 2023
https://issues.dlang.org/show_bug.cgi?id=23657
Issue ID: 23657
Summary: [REG2.101] Incorrect error escape reference to stack
allocated value
Product: D
Version: D2
Hardware: All
OS: All
Status: NEW
Severity: regression
Priority: P1
Component: dmd
Assignee: nobody at puremagic.com
Reporter: johanengelen at weka.io
Testcase succeeds with dmd <= 2.100, but fails since dmd 2.101
> ~/dcompilers/dmd-2.101.2/osx/bin/dmd -c -o- testcase.d
testcase.d(46): Error: escaping reference to stack allocated value returned by
`theLA().agent.members()`
I believe this diagnostic is incorrect, there is no escaping of a stack
allocated value. (but I am not 100.000% sure)
Testcase:
```
import std.algorithm: map;
import std.array: array;
struct SmallTable(K, V, ushort capacity) {
ushort _length = 5;
K[capacity] keys;
V[capacity] values;
auto byKey() {
return keys[0 .. _length];
}
}
struct SmallSet(K, ushort capacity) {
private alias V = ubyte[1];
private SmallTable!(K, V, capacity) table;
auto items() {
return table.byKey;
}
}
struct NodeId {
ushort value;
}
struct RaftId {
NodeId nodeId;
}
public struct RA {
SmallSet!(RaftId, 13) members() { return SmallSet!(RaftId, 13)(); }
}
class LA {
RA agent;
}
private __gshared LA leadAI = new LA();
ref auto theLA() {
return leadAI;
}
auto foo() {
return theLA.agent.members.items.map!(rid => rid.nodeId).array;
}
void main() {
int i = 0;
auto a = foo();
import std.stdio;
writeln("&i = ", &i);
writeln("&leadAI = ", &leadAI);
writeln("leadAI = ", cast(void*)leadAI);
writeln("a.ptr = ", a.ptr);
writeln("a.length = ", a.length);
writeln("a = ", a);
import core.memory : GC;
writeln("is_gc_allocated = ", GC.addrOf(a.ptr) != null);
}
```
--
More information about the Digitalmars-d-bugs
mailing list