Rubberduck icon indicating copy to clipboard operation
Rubberduck copied to clipboard

Using AddressOf a function should be considered a usage of the return value.

Open comintern opened this issue 8 years ago • 1 comments

Consider the following code:

Public Declare Function Foo Lib "foo.dll" Alias "FooW" (callback As LongPtr) As Long

Private Sub FooCaller()
    Debug.Print Foo(AddressOf Bar)
End Sub

Private Function Bar() As Long
    Bar = 42
End Function

Currently, this triggers a FunctionReturnValueNotUsedInspection result for Bar. But, there is absolutely no way to determine what the caller will do once a function has been converted into a function pointer. AFAIK there is no way of calling a function pointer natively in VBA, so it's safe to assume that it's going to be passed across a marshalling boundary. If someone has figured out how to do this in pure VBA, they're welcome to disable the inspection and show me HTH they managed to use a function pointer without an API call.

Given that it is impossible to know whether the return value is used from a callback invocation, I'd assert that it is better to err on the side of assuming that you wouldn't pass a function pointer to something that wasn't using the return.

Thoughts?

comintern avatar Dec 20 '16 04:12 comintern