Issue 11257 - Allow whole implicit conversion if one or more overlapped field could.
Summary: Allow whole implicit conversion if one or more overlapped field could.
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P2 enhancement
Assignee: No Owner
URL:
Keywords: pull
Depends on:
Blocks:
 
Reported: 2013-10-14 04:00 UTC by Kenji Hara
Modified: 2018-12-16 10:30 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 Kenji Hara 2013-10-14 04:00:35 UTC
Compiler rejects this code so the implicit conversion from const(R) to R breaks mutable field 'stripped' const-correctness.

struct R
{
    union
    {
        const(Object) original;
        Object stripped;
    }
}
void main()
{
    const R cr;
    R mr = cr;  // Error: cannot implicitly convert expression
                // (cr) of type const(R) to R
}

However, I think this is a little restricted behavior. Because qualified and overlapped field is D-specific feature. It's mostly used for bypassing the restriction of const qualifier. Therefore, in many case it would be protected by private access specifier.

The feature is necessary in order to allow const(Rebindable) to Rebindable conversion.
Comment 2 github-bugzilla 2013-10-14 20:51:11 UTC
Commit pushed to master at https://github.com/D-Programming-Language/dmd

https://github.com/D-Programming-Language/dmd/commit/0f00e6b6f29707f7a18b6e559aecf6bca50fca90
fix Issue 11257 - Allow whole implicit conversion if one or more overlapped field could.
Comment 3 Walter Bright 2018-12-16 09:55:20 UTC
I can't agree with this. A cast should be used to break out of const, and should not be allowed in @safe code.