Cannot check function address

Steven Schveighoffer schveiguy at gmail.com
Wed May 25 03:41:17 UTC 2022


On 5/24/22 11:14 PM, frame wrote:
> On Wednesday, 25 May 2022 at 02:42:26 UTC, Steven Schveighoffer wrote:

>> try:
>>
>> pragma(msg, typeof(fun));
> 
> Outputs:
> ```
> extern (C) void function(...)
> ```

OK, so it's a function pointer.

> 
> But the compiler would complain if I call it as a type? And how could it 
> call it later without an address to it - this works.

You don't need an address to call it. The compiler shouldn't complain at 
all, nor should it decide to think you are calling it without parentheses.


>> D should never call a function pointer without parentheses.
> 
> I'm very good in finding weird bugs ;-) Unfortunately, I cannot make an 
> example. I already tried some changes/simplifications but cannot 
> reproduce it outside the project.

I have encountered bugs like this (which disappear with seemingly 
unrelated removals). They are hard to deal with.

Have you tried [dustmite](https://code.dlang.org/packages/dustmite)? It 
can reduce D code down automatically to a smaller example, but be warned 
that if you get the condition wrong, and your code base is huge, it can 
take hours/days to whittle down to something that isn't what you want.

You can file a bug without a full example, just note that you have 
verified via the pragma(msg) statement above that the symbol is indeed a 
function pointer, and that compiler is trying to call it without 
explicit parentheses.

However, without a complete example, it's going to be hard to find/fix.

> But how can I help the compiler to use it as correct type? On invocation 
> with arguments all works fine, but checking if the pointer is not null 
> fails. It not even works with an assignment. Could some `static if()` 
> maybe help or some asm trick?

This is a compiler bug, at least I think so. Since the compiler is 
misbehaving, it's not clear how to make it behave.

-Steve


More information about the Digitalmars-d-learn mailing list