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

.tupleof sidesteps protection attributes #19498

Open
dlangBugzillaToGithub opened this issue Oct 22, 2018 · 4 comments
Open

.tupleof sidesteps protection attributes #19498

dlangBugzillaToGithub opened this issue Oct 22, 2018 · 4 comments

Comments

@dlangBugzillaToGithub
Copy link

Simen Kjaeraas reported this on 2018-10-22T14:08:26Z

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

CC List

Description

module foo;
struct S {
    private int i;
}
----
module bar;
import foo;
@safe unittest {
    S s;
    // Fails: struct `foo.S` member i is not accessible
    s.i++;
    // Fails: struct `foo.S` member i is not accessible
    __traits(getMember, s, "i")++;
    // Compiles just fine:
    s.tupleof[0]++;
}

This breaks guarantees about what's accessible from other modules, and can be used to break invariants relied on in @trusted code.

At the very least, this should not be @safe.

Related: issue 15371
@dlangBugzillaToGithub
Copy link
Author

doob (@jacob-carlborg) commented on 2018-10-22T18:47:00Z

I don't consider this a bug, I consider this a feature.

@dlangBugzillaToGithub
Copy link
Author

bugzilla (@WalterBright) commented on 2018-10-22T23:33:02Z

tupleof is known to break through private access protections. It should probably not be allowed in @safe code.

@dlangBugzillaToGithub
Copy link
Author

peter.alexander.au (@Poita) commented on 2018-10-22T23:55:50Z

It probably goes without saying, but many parts of Phobos use tupleof, so a generously sprinkling of @trusted would be needed. Likely this will break much 3rd party code although that is pure speculation on my part.

@dlangBugzillaToGithub
Copy link
Author

razvan.nitu1305 commented on 2023-04-28T10:53:18Z

It seems that now `__traits(getMember, s, "i")++;` also compiles. Does that mean that tupleof is also allowed or should we change this?

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