From 21870fa743efac9e850f8cdde64454ade07fe78f Mon Sep 17 00:00:00 2001 From: Niels Dekker Date: Tue, 26 Apr 2022 13:45:46 +0200 Subject: [PATCH] BUG: Replace `bit_cast` calls with `reinterpret_cast` It appears that commit 548b45f46dc9459bd9e6273a88485482794c3eaa ("BUG: Replace C-style casts from `_beginthreadex` with `bit_cast`", from pull request https://github.com/InsightSoftwareConsortium/ITK/pull/3380) was wrong: `bit_cast` might do a different conversion than the corresponding C-style cast, `(HANDLE)`. The C-style cast `(HANDLE)` behaves exactly like `reinterpret_cast`, by definition. `reinterpret_cast` does an implementation-defined conversion, as was explained by Jonathan Wakely at https://github.com/isocpp/CppCoreGuidelines/issues/1517#issuecomment-1104120989 (issue "Favor bit_cast over reinterpret_cast"). Fixed by replacing all `bit_cast` calls with `reinterpret_cast`. --- .../Common/src/itkPlatformMultiThreaderWindows.cxx | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/Modules/Core/Common/src/itkPlatformMultiThreaderWindows.cxx b/Modules/Core/Common/src/itkPlatformMultiThreaderWindows.cxx index 628b5aae309..57dab826fdd 100644 --- a/Modules/Core/Common/src/itkPlatformMultiThreaderWindows.cxx +++ b/Modules/Core/Common/src/itkPlatformMultiThreaderWindows.cxx @@ -26,7 +26,6 @@ * *=========================================================================*/ #include "itkPlatformMultiThreader.h" -#include "itkBitCast.h" #include "itkObjectFactory.h" #include "itksys/SystemTools.hxx" #include @@ -72,7 +71,7 @@ PlatformMultiThreader::MultipleMethodExecute() m_ThreadInfoArray[threadCount].UserData = m_MultipleData[threadCount]; m_ThreadInfoArray[threadCount].NumberOfWorkUnits = m_NumberOfWorkUnits; - processId[threadCount] = bit_cast(_beginthreadex( + processId[threadCount] = reinterpret_cast(_beginthreadex( nullptr, 0, m_MultipleMethod[threadCount], &m_ThreadInfoArray[threadCount], 0, (unsigned int *)&threadId)); if (processId[threadCount] == nullptr) @@ -137,8 +136,8 @@ PlatformMultiThreader::SpawnThread(ThreadFunctionType f, void * UserData) // Using _beginthreadex on a PC // - m_SpawnedThreadProcessID[id] = - bit_cast(_beginthreadex(nullptr, 0, f, &m_SpawnedThreadInfoArray[id], 0, (unsigned int *)&threadId)); + m_SpawnedThreadProcessID[id] = reinterpret_cast( + _beginthreadex(nullptr, 0, f, &m_SpawnedThreadInfoArray[id], 0, (unsigned int *)&threadId)); if (m_SpawnedThreadProcessID[id] == nullptr) { itkExceptionMacro("Error in thread creation !!!"); @@ -177,8 +176,8 @@ PlatformMultiThreader::SpawnDispatchSingleMethodThread(PlatformMultiThreader::Wo { // Using _beginthreadex on a PC DWORD threadId; - auto threadHandle = - bit_cast(_beginthreadex(nullptr, 0, this->SingleMethodProxy, threadInfo, 0, (unsigned int *)&threadId)); + auto threadHandle = reinterpret_cast( + _beginthreadex(nullptr, 0, this->SingleMethodProxy, threadInfo, 0, (unsigned int *)&threadId)); if (threadHandle == nullptr) { itkExceptionMacro("Error in thread creation !!!");