Bug 19934 – template function inference breaks when taking the address of the function inside the template

Status
NEW
Severity
normal
Priority
P3
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2019-06-02T05:31:50Z
Last change time
2024-12-13T19:03:42Z
Assigned to
No Owner
Creator
Jonathan Marler
Moved to GitHub: dmd#19575 →

Comments

Comment #0 by johnnymarler — 2019-06-02T05:31:50Z
Reproduce issue with: ``` void func()() { pragma(msg, typeof(&func!()).stringof); } void main() @nogc { auto funcPtr = &func!(); funcPtr(); } ``` This fails with: Error: `@nogc` function `D main` cannot call non-@nogc function pointer `funcPtr` Normally `func` would be @nogc here, but when DMD is forced to resolve typeof(&func!()) while analyzing func, it causes an issue template inference. Note that this issue occurs for all function attributes such as `pure` and `nothrow`. Note that any of the following modifications will fix the issue: 1. remove the pragma, if dmd doesn't have to resolve typeof(&func) inside of func then attribute inference still works correctly 2. don't use auto for funcPtr, i.e. void main() @nogc { void function() @nogc funcPtr = &func!(); funcPtr(); } 3. call the function pointer without assigning it to a variable: void main() @nogc { (&func!())(); } 3. call func directly instead of through a function pointer: void main() @nogc { func!()(); }
Comment #1 by robert.schadek — 2024-12-13T19:03:42Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/19575 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB