Bug 19961 – context pointer does not apply qualifiers properly

Status
NEW
Severity
major
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2019-06-14T08:05:25Z
Last change time
2024-12-13T19:03:57Z
Keywords
accepts-invalid, rejects-valid
Assigned to
No Owner
Creator
Nicholas Wilson
Moved to GitHub: dmd#17909 →

Comments

Comment #0 by iamthewilsonator — 2019-06-14T08:05:25Z
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 by iamthewilsonator — 2019-06-14T08:09:45Z
Bleaugh. That should be auto dg2 = delegate int() const { return *p++; };
Comment #2 by iamthewilsonator — 2019-06-14T08:10:19Z
Bleaugh. That should be auto dg2 = delegate int() const { return *p++; };
Comment #3 by bugzilla — 2019-06-14T09:58:24Z
Comment #4 by iamthewilsonator — 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 } }
Comment #5 by robert.schadek — 2024-12-13T19:03:57Z
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