Re: [PATCH cb/pedantic-build-for-developers] lazyload.h: fix warnings about mismatching function pointer types

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Am 22.09.21 um 22:16 schrieb Carlo Arenas:
> On Wed, Sep 22, 2021 at 12:56 PM Johannes Sixt <j6t@xxxxxxxx> 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.

> 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



[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux