D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 7636 - const hole for implicit conversion to base class
Summary: const hole for implicit conversion to base class
Status: RESOLVED DUPLICATE of issue 3731
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P2 normal
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-03-03 16:17 UTC by Martin Nowak
Modified: 2012-03-04 05:19 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Martin Nowak 2012-03-03 16:17:19 UTC
class Base
{
    int _val;
}

class Foo : Base
{
    Base base() const { return this; }
}

void main()
{
    const(Foo) foo = new const(Foo);
    static assert(!__traits(compiles, foo._val = 1));
    static assert(!__traits(compiles, foo.base()._val = 1));
    foo.base()._val = 1;
    assert(foo._val == 0);
}

Also broken for immutable and shared.
--------

This is probably implemented as 'return cast(Base)this;' and
needs to include the right modifiers.
Comment 1 yebblies 2012-03-03 20:59:53 UTC
Is this just 3731?
Comment 2 Martin Nowak 2012-03-04 05:19:41 UTC

*** This issue has been marked as a duplicate of issue 3731 ***