[clang] Split -Wcast-function-type into a separate group (PR #86131)

Aaron Ballman via cfe-commits cfe-commits at lists.llvm.org
Mon Apr 14 05:50:12 PDT 2025


AaronBallman wrote:

> This warning creates issues under Windows, where reinterpret-casting from FARPROC to the actual function type is common.
> 
> #92738 [boostorg/interprocess#259](https://github.com/boostorg/interprocess/issues/259)
> 
> Reinterpret-casting a function pointer to another function pointer type, then back to the original, is well defined in C++. In contrast, using `void*` for the same purpose is not.

I think the diagnostic is working as expected in this case -- we cannot tell that the user is doing a round-trip cast, we can only see there's a single cast between incompatible function pointer types.
```
warning: cast from 'FARPROC' (aka 'int (*)() __attribute__((stdcall))') to
'GetSystemTimeAsFileTimePtr' (aka 'void (*)(_FILETIME *) __attribute__((stdcall))')
converts to incompatible function type [-Wcast-function-type-mismatch]
```
or
```
2025-03-12T16:47:36.5368174Z .\boost/interprocess/detail/win32_api.hpp(1122,59): error: cast from 'farproc_t' (aka 'int (*)() __attribute__((stdcall))') to 'NtQuerySystemInformation_t' (aka 'long (*)(int, void *, unsigned long, unsigned long *) __attribute__((stdcall))') converts to incompatible function type [-Werror,-Wcast-function-type-mismatch]
2025-03-12T16:47:36.5371616Z  1122 |    NtQuerySystemInformation_t pNtQuerySystemInformation = reinterpret_cast<NtQuerySystemInformation_t>
2025-03-12T16:47:36.5373049Z       |                                                           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2025-03-12T16:47:36.5373933Z  1123 |          (dll_func::get(dll_func::NtQuerySystemInformation));
```
is exactly what this is intended to diagnose. Did you have a change in mind you'd like to see?

https://github.com/llvm/llvm-project/pull/86131


More information about the cfe-commits mailing list