[Issue 24485] New: Invalid implicit ref return reinterpret cast for structs with copy constructor
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Sat Apr 6 11:19:07 UTC 2024
https://issues.dlang.org/show_bug.cgi?id=24485
Issue ID: 24485
Summary: Invalid implicit ref return reinterpret cast for
structs with copy constructor
Product: D
Version: D2
Hardware: All
OS: All
Status: NEW
Keywords: accepts-invalid
Severity: critical
Priority: P1
Component: dmd
Assignee: nobody at puremagic.com
Reporter: sludwig at outerproduct.org
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.
--
More information about the Digitalmars-d-bugs
mailing list