Bug 22979 – "Pointers-to-member" with attributes

Status
NEW
Severity
normal
Priority
P3
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
Mac OS X
Creation time
2022-04-03T16:43:48Z
Last change time
2024-12-13T19:21:57Z
Assigned to
No Owner
Creator
tyckesak
Depends on
17080
Moved to GitHub: dmd#20079 →

Comments

Comment #0 by josipp — 2022-04-03T16:43:48Z
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 with > Error: 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 with > Error: `const`/`immutable`/`shared`/`inout`/`return` attributes are 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?
Comment #1 by robert.schadek — 2024-12-13T19:21:57Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/20079 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB