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

can break immutable with postblit #19376

Open
dlangBugzillaToGithub opened this issue Feb 2, 2018 · 3 comments
Open

can break immutable with postblit #19376

dlangBugzillaToGithub opened this issue Feb 2, 2018 · 3 comments

Comments

@dlangBugzillaToGithub
Copy link

ag0aep6g reported this on 2018-02-02T11:58:46Z

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

CC List

  • Ate Eskola
  • Andrei Alexandrescu (@andralex)
  • Ketmar Dark

Description

----
struct S
{
    int* x;
    this(this) @safe { *x = 13; }
}

void main() @safe
{
    immutable int* x = new int(42);
    assert(*x == 42); /* passes */
    auto s = immutable S(x);
    auto s2 = s; /* should be rejected */
    assert(*x == 42); /* fails */
}
----
@dlangBugzillaToGithub
Copy link
Author

ag0aep6g commented on 2018-03-06T12:56:29Z

*** Issue 18561 has been marked as a duplicate of this issue. ***

@dlangBugzillaToGithub
Copy link
Author

andrei (@andralex) commented on 2018-03-19T15:57:47Z

A similar example shows fetching a mutable pointer to immutable data:

----
int* g;

struct S
{
    int* x;
    this(this) { g = x; }
}

void main()
{
    immutable int* x = new int(42);
    assert(*x == 42); /* passes */
    auto s = immutable S(x);
    auto s2 = s; /* should be rejected */
}

@dlangBugzillaToGithub
Copy link
Author

dfj1esp02 commented on 2018-04-03T07:45:44Z

Postblit should respect type qualifiers the same way const constructor does.

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