digitalmars.D.bugs - [Issue 22979] New: "Pointers-to-member" with attributes
- d-bugmail puremagic.com (55/57) Apr 03 2022 https://issues.dlang.org/show_bug.cgi?id=22979
https://issues.dlang.org/show_bug.cgi?id=22979 Issue ID: 22979 Summary: "Pointers-to-member" with attributes Product: D Version: D2 Hardware: x86_64 OS: Mac OS X Status: NEW Severity: normal Priority: P1 Component: dmd Assignee: nobody puremagic.com Reporter: josipp live.de Hi all, I am aware of the nonsensical delegate -> function conversion sequence for non-static member functions, as demonstrated by ```d class Class { int doubling(int x) { return x * 2; } } void main() { int function(int) fptr = &Class.doubling; // typechecks! } ``` However, there is some deeper unsound compiler reasoning going on. Consider ```d // vvvvv notice the member fn attribute class Class { int doubling(int x) inout { return x * 2; } } void main() { int function(int) fptr = &Class.doubling; } ``` dmd fails withError: cannot implicitly convert expression `& doubling`of type `int function(int x) inout` to `int function(int)` Adjust the type of fptr it shall be then. Alas... no. ```d [...] void main() { int function(int) inout fptr = &Class.doubling; } ``` fails withError: `const`/`immutable`/`shared`/`inout`/`return` attributesare only valid for non-static member functions But when done with `auto`, it says ```d [...] void main() { auto fptr = &Class.doubling; pragma(msg, typeof(fptr)); // int function(int) inout } ``` What gives? --
Apr 03 2022