Bug 23404 – CTFE evaluation is unecessary when passing function return type as aliased template argument

Status
RESOLVED
Resolution
INVALID
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2022-10-10T20:26:10Z
Last change time
2022-10-14T16:26:33Z
Assigned to
No Owner
Creator
Luís Ferreira

Comments

Comment #0 by contact — 2022-10-10T20:26:10Z
The following doesn't compile, as it fails on `bar()` call because it doesn't have the source code. Although it should. ``` void bar(); int foo()() { bar(); return 1; } void weird(alias func)() {} void main() { weird!(foo()); } ``` Although, changing the line 15 to `weird!(foo!())`, it starts working. Eventhough they are different semantics, the CTFE engine is running unnecessarily on the first situation, where there's no need to `weird` being CTFE-able. This can particularly a problem for `core.lifetime.forward!()` when, you want to forward ref return types.
Comment #1 by ag0aep6g — 2022-10-11T05:20:51Z
You're not passing `foo`'s return *type* to `weird`. You're trying to pass its return *value*. For that, the function must go through CTFE. As far as I can see, there is no bug here. Closing as invalid.
Comment #2 by contact — 2022-10-14T16:26:33Z
(In reply to ag0aep6g from comment #1) > You're not passing `foo`'s return *type* to `weird`. You're trying to pass > its return *value*. For that, the function must go through CTFE. > > As far as I can see, there is no bug here. Closing as invalid. Well I thought that this was possible: ``` void bar(); int foo()() { bar(); return 1; } void weird(alias func)() {} void main() { alias func = foo(); } ``` But it fails too. To be clear, I'm not expecting it to be the return type but the template instance, but there's nothing to be CTFEable here.