Bug 24485 – Invalid implicit ref return reinterpret cast for structs with copy constructor
Status
RESOLVED
Resolution
FIXED
Severity
critical
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2024-04-06T11:19:07Z
Last change time
2024-04-10T12:44:47Z
Keywords
accepts-invalid, pull
Assigned to
No Owner
Creator
Sönke Ludwig
Comments
Comment #0 by sludwig — 2024-04-06T11:19:07Z
The following code compiles without errors and implicitly casts a reference to an A to a reference to any other type:
---
struct A {
int i = 43;
this(ref A rhs) {}
}
struct B {
int i = 42;
}
ref B foo() { auto a = new A; return *a; } // should not compile
struct C {
A a;
@property ref B b() { return a; } // should not compile
}
void main()
{
C c;
assert(c.b.i == 42); // if anything, B.i should always be 42
}
---
This issue has been introduced in 2.086.0 as part of the copy constructor feature.
Comment #1 by dlang-bot — 2024-04-08T11:38:23Z
@RazvanN7 created dlang/dmd pull request #16364 "Fix Bugzilla 24485 - Invalid implicit ref return reinterpret cast for structs with copy constructor" fixing this issue:
- Fix Bugzilla 24485 - Invalid implicit ref return reinterpret cast for structs with copy constructor
https://github.com/dlang/dmd/pull/16364
Comment #2 by dlang-bot — 2024-04-10T12:44:47Z
dlang/dmd pull request #16364 "Fix Bugzilla 24485 - Invalid implicit ref return reinterpret cast for structs with copy constructor" was merged into master:
- a93a57e74b0ce82e6c01b8ca64bfed2ddbeabc0b by RazvanN7:
Fix Bugzilla 24485 - Invalid implicit ref return reinterpret cast for structs with copy constructor
https://github.com/dlang/dmd/pull/16364