Skip to content

Commit

Permalink
[libcxx] Add cast to avoid pointer casting warning on Windows
Browse files Browse the repository at this point in the history
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
999d4f8, 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.)
  • Loading branch information
mstorsjo committed May 20, 2024
1 parent 9f449c3 commit fa65e83
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions libcxx/src/chrono.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit fa65e83

Please sign in to comment.