D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 19961 - context pointer does not apply qualifiers properly
Summary: context pointer does not apply qualifiers properly
Status: NEW
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P2 major
Assignee: No Owner
URL:
Keywords: accepts-invalid, rejects-valid
Depends on:
Blocks:
 
Reported: 2019-06-14 08:05 UTC by Nicholas Wilson
Modified: 2024-12-13 19:03 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 Nicholas Wilson 2019-06-14 08:05:25 UTC
void main()
{
    int i = 42;    
    // const should not be able to access mutable.
    int* p = &i;
    auto dg2 = delegate int() const { return *p; };
    assert(dg2() == i);
}

fails to error.

Also 

void main()
{
    int i = 42;    
    // shared cannot access mutable
    int* p = &i;
    auto dg2 = delegate int() shared { return *p; };
    assert(dg2() == i);
}

errors, the context should be captured as shared so that should be allowed. Issue 15306 declared this accepts invalid as shared aliasing but I believe that is incorrect. Shared doesn't offer any useful guaruntees on that front anyway.
Comment 1 Nicholas Wilson 2019-06-14 08:09:45 UTC
Bleaugh. That should be 
auto dg2 = delegate int() const { return *p++; };
Comment 2 Nicholas Wilson 2019-06-14 08:10:19 UTC
Bleaugh. That should be 
auto dg2 = delegate int() const { return *p++; };
Comment 3 Walter Bright 2019-06-14 09:58:24 UTC
Partial fix: https://github.com/dlang/dmd/pull/10035
Comment 4 Nicholas Wilson 2019-06-17 12:55:12 UTC
So the real issue is:

struct S
{
    int x;
    void foo() const
    {
        pragma(msg, typeof(x)); // const(int)
    }
}

void test()
{
    void nested() const
    {
        pragma(msg, typeof(x)); // int
    }
}
Comment 5 dlangBugzillaToGithub 2024-12-13 19:03:57 UTC
THIS ISSUE HAS BEEN MOVED TO GITHUB

https://github.com/dlang/dmd/issues/17909

DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB