CTFE limitation on reinterpreting cast
Nick Treleaven
nick at geany.org
Wed Sep 30 19:15:33 UTC 2026
On Monday, 28 September 2026 at 23:35:24 UTC, Rambutan wrote:
> I have had no trouble doing this with function pointers
> earlier. Here's a meaningless small example.
> ```
> extern(C) int f1() { return 0; }
>
> __gshared auto f2 = cast(int function(int,char*))&f1;
>
> void main() {}
> ```
> This compiles just fine.
I think its a compiler bug. The cast above should be a compile
error, because the pointer types are not covariant. Now filed:
https://github.com/dlang/dmd/issues/23950.
The compiler was ignoring the parameter types and linkage, but it
did check the return type. The following errors with stable dmd:
```d
int f1() { return 0; }
auto fp = cast(void function()) &f1; // Error: reinterpreting
cast from `int()*` to `void()*` is not supported in CTFE
```
More information about the Digitalmars-d
mailing list