www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 24485] New: Invalid implicit ref return reinterpret cast for

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 puremagic.com
          Reporter: sludwig 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.

--
Apr 06