COMP: Silence nodiscard warnings for Future.get() in PoolMultiThreader#5945
COMP: Silence nodiscard warnings for Future.get() in PoolMultiThreader#5945hjmjohnson wants to merge 1 commit intoInsightSoftwareConsortium:mainfrom
Conversation
82e1b97 to
fcbbe4e
Compare
fcbbe4e to
2f3d4e1
Compare
Cast Future.get() return values to void where the call is only used for its side effect of waiting for thread completion and propagating exceptions. Fixes the following warnings: ``` ITK/Modules/Core/Common/src/itkPoolMultiThreader.cxx:148:55: warning: ignoring return value of function declared with 'nodiscard' attribute [-Wunused-result] ITK/Modules/Core/Common/src/itkPoolMultiThreader.cxx:303:11: warning: ignoring return value of function declared with 'nodiscard' attribute [-Wunused-result] This is for clang-22 compilers. ``` Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2f3d4e1 to
32c6b1d
Compare
| for (threadLoop = 1; threadLoop < m_NumberOfWorkUnits; ++threadLoop) | ||
| { | ||
| exceptionHandler.TryAndCatch([this, threadLoop] { m_ThreadInfoArray[threadLoop].Future.get(); }); | ||
| exceptionHandler.TryAndCatch([this, threadLoop] { (void)m_ThreadInfoArray[threadLoop].Future.get(); }); |
There was a problem hiding this comment.
What does Future.get() return? And why is it OK to ignore its return value?
I'm asking, because maybe we should use the std::future<void> specialization, for Future: https://en.cppreference.com/w/cpp/thread/future/get.html
std::future<void>::get() returns void. It looks like that's what we want, right?
In general, I think it's preferable to avoid unnecessary casting 🤷
There was a problem hiding this comment.
std::future<ITK_THREAD_RETURN_TYPE> Future;ITK_THREAD_RETURN_TYPE depends on the platform.
I don't understand what you are suggesting. Could you please make an alternate proposal?
There was a problem hiding this comment.
Ah, I see:
ITK_THREAD_RETURN_TYPE is a pointer type when using Pthreads:
And it's unsigned int when using WIN32 threads:
But "normally" it's just void:
Are Pthreads and WIN32 threads both still actively supported nowadays?
N-Dekker
left a comment
There was a problem hiding this comment.
Could you please make an alternate proposal?
Please wait, I'll give it a try.
N-Dekker
left a comment
There was a problem hiding this comment.
Please wait, I'll try an alternative.
`Future` was declared as `std::future<ITK_THREAD_RETURN_TYPE>`, which is platform specific, and caused warnings on some platforms, as reported by Hans Johnson at InsightSoftwareConsortium#5945 : itkPoolMultiThreader.cxx:148:55: warning: ignoring return value of function declared with 'nodiscard' attribute [-Wunused-result] exceptionHandler.TryAndCatch([this, threadLoop] { m_ThreadInfoArray[threadLoop].Future.get(); }); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Addressed by using `std::future<void>` instead.
`Future` was declared as `std::future<ITK_THREAD_RETURN_TYPE>`, which is platform specific, and caused warnings on some platforms, as reported by Hans Johnson at InsightSoftwareConsortium#5945 : itkPoolMultiThreader.cxx:148:55: warning: ignoring return value of function declared with 'nodiscard' attribute [-Wunused-result] exceptionHandler.TryAndCatch([this, threadLoop] { m_ThreadInfoArray[threadLoop].Future.get(); }); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Addressed by using `std::future<void>` instead.
`Future` was declared as `std::future<ITK_THREAD_RETURN_TYPE>`, which is platform specific, and caused warnings on some platforms, as reported by Hans Johnson at InsightSoftwareConsortium#5945 : itkPoolMultiThreader.cxx:148:55: warning: ignoring return value of function declared with 'nodiscard' attribute [-Wunused-result] exceptionHandler.TryAndCatch([this, threadLoop] { m_ThreadInfoArray[threadLoop].Future.get(); }); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Addressed by replacing the public `ThreadPoolInfoStruct` with a private `InternalWorkUnitInfo` struct, which has its `Future` declared as `std::future<void>`.
`Future` was declared as `std::future<ITK_THREAD_RETURN_TYPE>`, which is platform specific, and caused warnings on some platforms, as reported by Hans Johnson at InsightSoftwareConsortium#5945 : itkPoolMultiThreader.cxx:148:55: warning: ignoring return value of function declared with 'nodiscard' attribute [-Wunused-result] exceptionHandler.TryAndCatch([this, threadLoop] { m_ThreadInfoArray[threadLoop].Future.get(); }); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Addressed by replacing the public `ThreadPoolInfoStruct` with a private `InternalWorkUnitInfo` struct, which has its `Future` declared as `std::future<void>`.
|
Superceeded by |
Summary
Future.get()return values to(void)initkPoolMultiThreader.cxxwhere the call is only used for its side effect of waiting for thread completion and propagating exceptionsFixes:
Test plan
-Wunused-resultwarnings(void)cast only suppresses the warning🤖 Generated with Claude Code