[Issue 14141] New: `pure` member function returning qualified member result is implicitly convertible to unqualified

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Sat Feb 7 08:25:12 PST 2015


https://issues.dlang.org/show_bug.cgi?id=14141

          Issue ID: 14141
           Summary: `pure` member function returning qualified member
                    result is implicitly convertible to unqualified
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Keywords: accepts-invalid
          Severity: major
          Priority: P1
         Component: DMD
          Assignee: nobody at puremagic.com
          Reporter: verylonglogin.reg at gmail.com

This code should compile:
---
struct S
{
    Object obj;

    const(Object) getObj() const pure
    { return obj; }
}

void main()
{
    const S s;
    static assert(is(typeof(s.getObj()) == const Object));           // ok
    static assert(!__traits(compiles, { Object o = s.getObj(); }));  // fails
}
---

As a result such function compiles but shouldn't:
---
Object f(const Object o)
{
    const S s = { obj: o };
    return s.getObj();
}
---

This results in type system breakage.

--


More information about the Digitalmars-d-bugs mailing list