1
0
Fork 0
mirror of https://git.tukaani.org/xz.git synced 2024-04-04 12:36:23 +02:00

tuklib_physmem: Clean up the way -Wcast-function-type is silenced on Windows.

__has_warning and other __has_foo macros are meant to become
compiler-agnostic so it's not good to check for __clang__ with it.

This also relied on tuklib_common.h for #defining __has_warning
which was confusing as #defining reserved macros is generally
not a good idea.
This commit is contained in:
Lasse Collin 2023-01-23 23:38:34 +02:00 committed by Jia Tan
parent 683a3c7e2f
commit 8366cf8738

View file

@ -73,6 +73,17 @@
#endif #endif
// With GCC >= 8.1 with -Wextra and Clang >= 13 with -Wcast-function-type
// will warn about the Windows-specific code.
#if TUKLIB_GNUC_REQ(8,1)
# define CAN_DISABLE_WCAST_FUNCTION_TYPE 1
#elif defined(__has_warning)
# if __has_warning("-Wcast-function-type")
# define CAN_DISABLE_WCAST_FUNCTION_TYPE 1
# endif
#endif
extern uint64_t extern uint64_t
tuklib_physmem(void) tuklib_physmem(void)
{ {
@ -87,15 +98,13 @@ tuklib_physmem(void)
HMODULE kernel32 = GetModuleHandle(TEXT("kernel32.dll")); HMODULE kernel32 = GetModuleHandle(TEXT("kernel32.dll"));
if (kernel32 != NULL) { if (kernel32 != NULL) {
typedef BOOL (WINAPI *gmse_type)(LPMEMORYSTATUSEX); typedef BOOL (WINAPI *gmse_type)(LPMEMORYSTATUSEX);
#if TUKLIB_GNUC_REQ(8,1) || (defined(__clang__) \ #ifdef CAN_DISABLE_WCAST_FUNCTION_TYPE
&& __has_warning("-Wcast-function-type"))
# pragma GCC diagnostic push # pragma GCC diagnostic push
# pragma GCC diagnostic ignored "-Wcast-function-type" # pragma GCC diagnostic ignored "-Wcast-function-type"
#endif #endif
gmse_type gmse = (gmse_type)GetProcAddress( gmse_type gmse = (gmse_type)GetProcAddress(
kernel32, "GlobalMemoryStatusEx"); kernel32, "GlobalMemoryStatusEx");
#if TUKLIB_GNUC_REQ(8,1) || (defined(__clang__) \ #ifdef CAN_DISABLE_WCAST_FUNCTION_TYPE
&& __has_warning("-Wcast-function-type"))
# pragma GCC diagnostic pop # pragma GCC diagnostic pop
#endif #endif
if (gmse != NULL) { if (gmse != NULL) {