dstep
dstep copied to clipboard
const attribute is removed from parameter of a function pointer
I ran into this when translating the following:
typedef void (*AStorageManager_obbCallbackFunc)(const char* filename, const int32_t state, void* data);
DStep turned it into this, removing the const for the second parameter:
alias void function (const(char)*, int, void*) AStorageManager_obbCallbackFunc;
I haven't checked to see if dmd will actually complain about this, but it strikes me as a bug.
DStep turned it into this, removing the const for the second parameter
This looks a bit odd. But according to libclang, which DStep uses under the hood, state
is not const.
I haven't checked to see if dmd will actually complain about this
Why would DMD complain about this?
Hmm, if I remove the typedef, i.e. during it into a variable declaration, libclang will see it as const.
I've asked about this on the Clang mailing list.
Why would DMD complain about this?
Because the callback signature doesn't match the C library? I've had that happen in other situations, not sure if it would here. If you mean that it's the linker that normally catches stuff like this, sure.
Hmm, if I remove the typedef, i.e. during it into a variable declaration, libclang will see it as const.
Yeah, if you turn it into an actual function declaration, it sees the parameter as const, just not when it's a function pointer.
Because the callback signature doesn't match the C library? I've had that happen in other situations, not sure if it would here. If you mean that it's the linker that normally catches stuff like this, sure.
Right, when you use the function pointer. Yes, then DMD will complain.
Yeah, if you turn it into an actual function declaration, it sees the parameter as const, just not when it's a function pointer.
It's not the function pointer that is the problem, it's the typedef.
I got a reply [1] from the mailing list and this is apparently how C behaves. I'm not sure that I can do anything about it.
[1] http://clang-developers.42468.n3.nabble.com/const-stripped-in-typedefs-for-parameters-of-primitive-type-td4041337.html
Perhaps D should allow the callbacks anyway since const
doesn't really matter for value types.
I have no real inclination on what to do here, I wasn't even sure it was a bug. I just reported it as I was double-checking the translation and it seemed like it might be.
It behaves as it should according to C. But that will cause problems on the D side. I really, really don't want to parse C code without the help of Clang.