[libcxx-commits] [libcxx] [libcxx] Add cast to avoid pointer casting warning on Windows (PR #92738)

Martin Storsjö via libcxx-commits libcxx-commits at lists.llvm.org
Mon May 20 04:24:56 PDT 2024


https://github.com/mstorsjo updated https://github.com/llvm/llvm-project/pull/92738

>From fa65e837b1da261570d1fe1ac6df643096afc0ec Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Martin=20Storsj=C3=B6?= <martin at martin.st>
Date: Sun, 19 May 2024 00:43:06 +0300
Subject: [PATCH] [libcxx] Add cast to avoid pointer casting warning on Windows

This avoids the following build time warning, when building with
the latest nightly Clang:

    warning: cast from 'FARPROC' (aka 'int (*)() __attribute__((stdcall))') to
    'GetSystemTimeAsFileTimePtr' (aka 'void (*)(_FILETIME *) __attribute__((stdcall))')
    converts to incompatible function type [-Wcast-function-type-mismatch]

This warning seems to have appeared since Clang commit
999d4f840777bf8de26d45947192aa0728edc0fb, which restructured.

The GetProcAddress function returns a FARPROC type, which is
"int (WINAPI *)()". Directly casting this to another function pointer
type triggers this warning, but casting to a void* inbetween
avoids this issue. (On Unix-like platforms, dlsym returns a
"void*", which doesn't exhibit this casting problem.)
---
 libcxx/src/chrono.cpp | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/libcxx/src/chrono.cpp b/libcxx/src/chrono.cpp
index e7d6dfbc22924..83e8a64504ae0 100644
--- a/libcxx/src/chrono.cpp
+++ b/libcxx/src/chrono.cpp
@@ -77,8 +77,8 @@ typedef void(WINAPI* GetSystemTimeAsFileTimePtr)(LPFILETIME);
 class GetSystemTimeInit {
 public:
   GetSystemTimeInit() {
-    fp =
-        (GetSystemTimeAsFileTimePtr)GetProcAddress(GetModuleHandleW(L"kernel32.dll"), "GetSystemTimePreciseAsFileTime");
+    fp = (GetSystemTimeAsFileTimePtr)(void*)GetProcAddress(
+        GetModuleHandleW(L"kernel32.dll"), "GetSystemTimePreciseAsFileTime");
     if (fp == nullptr)
       fp = GetSystemTimeAsFileTime;
   }



More information about the libcxx-commits mailing list