Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

context pointer does not apply qualifiers properly #17909

Open
dlangBugzillaToGithub opened this issue Jun 14, 2019 · 4 comments
Open

context pointer does not apply qualifiers properly #17909

dlangBugzillaToGithub opened this issue Jun 14, 2019 · 4 comments

Comments

@dlangBugzillaToGithub
Copy link

Nicholas Wilson (@thewilsonator) reported this on 2019-06-14T08:05:25Z

Transferred from https://issues.dlang.org/show_bug.cgi?id=19961

CC List

Description

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.
@dlangBugzillaToGithub
Copy link
Author

iamthewilsonator commented on 2019-06-14T08:09:45Z

Bleaugh. That should be 
auto dg2 = delegate int() const { return *p++; };

@dlangBugzillaToGithub
Copy link
Author

iamthewilsonator commented on 2019-06-14T08:10:19Z

Bleaugh. That should be 
auto dg2 = delegate int() const { return *p++; };

@dlangBugzillaToGithub
Copy link
Author

bugzilla (@WalterBright) commented on 2019-06-14T09:58:24Z

Partial fix: https://github.com/dlang/dmd/pull/10035

@dlangBugzillaToGithub
Copy link
Author

iamthewilsonator commented on 2019-06-17T12:55:12Z

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
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant