Re: [PATCH cb/pedantic-build-for-developers] lazyload.h: fix warnings about mismatching function pointer types
- From
Johannes Sixt <j6t@kdbg.org>
- Date
- Sep 22, 2021, 21:21 UTC
- Message-ID
- <2793c9c0-57ee-c7e0-957c-01d9aa27b44b@kdbg.org>
- In-Reply-To
- <CAPUEspguHsx+BtViT5tO3eyZSJf7mJ0of-K3vAMqB0-ju4fpsg@mail.gmail.com>
Am 22.09.21 um 22:16 schrieb Carlo Arenas:
Show 18 quoted lines
> On Wed, Sep 22, 2021 at 12:56 PM Johannes Sixt <j6t@kdbg.org> wrote:
>>
>> Here, GCC warns about every use of the INIT_PROC_ADDR macro, for example:
>>
>> In file included from compat/mingw.c:8:
>> compat/mingw.c: In function 'mingw_strftime':
>> compat/win32/lazyload.h:38:12: warning: assignment to
>> 'size_t (*)(char *, size_t, const char *, const struct tm *)'
>> {aka 'long long unsigned int (*)(char *, long long unsigned int,
>> const char *, const struct tm *)'} from incompatible pointer type
>> 'FARPROC' {aka 'long long int (*)()'} [-Wincompatible-pointer-types]
>> 38 | (function = get_proc_addr(&proc_addr_##function))
>> | ^
>> compat/mingw.c:1014:6: note: in expansion of macro 'INIT_PROC_ADDR'
>> 1014 | if (INIT_PROC_ADDR(strftime))
>> | ^~~~~~~~~~~~~~
>
> did you have CFLAGS adding -Wincompatible-pointer-types explicitly?I don't know of the top of my head (am not at that Windows box right now). I am fairly certain that I do not have DEVELOPER set.
Show 9 quoted lines
> This is the reason why the code that got merged to master had -Wno > for this case. > >> (message wrapper for convenience). Insert a cast to keep the compiler >> happy. A cast is fine in these cases because they are generic function >> pointer values that have been looked up in a DLL. > > I have a more complete "fix" which I got stuck testing GGG[1]; you are likely > going to also hit -Wcast-function-type otherwise.
I think that the correct solution is that get_proc_addr() returns void*, not FARPROC. Then either no cast is needed (because void* can be converted to function pointer type implicitly) or a cast is needed and that is then not between incompatible function pointer types and should not trigger -Wcast-function-type, theoretically.
>> --- >> How can this have worked ever without a warning? > > POSIX have a specific exception that allows (void *) for this,...
Sure, but as you can see in the warning message, FARPROC is not void*, but a somewhat generic function pointer type. I was not questioning the assignment of function pointer values of different types, but the absence of a warning.
-- Hannes