KWSys: use allocator_traits::rebind_alloc for C++20 (hashtable.hxx)#6513
KWSys: use allocator_traits::rebind_alloc for C++20 (hashtable.hxx)#6513gdevenyi wants to merge 1 commit into
Conversation
std::allocator::rebind was deprecated in C++17 and removed in C++20, so libstdc++ in newer toolchains (e.g. GCC 14/15 on Fedora 44) no longer provides _Alloc::rebind, breaking the hash_map/hash_set hashtable template: error: no type named 'other' in 'std::allocator<...>::rebind<...>' Replace the three `typename _Alloc::template rebind<X>::other` typedefs with the C++11 `std::allocator_traits<_Alloc>::template rebind_alloc<X>`, which is the standard replacement and works on all supported standards. <memory> is already included.
|
Has something similar already been applied upstream? Should we update KWSys in 4.14 branch, instead of patching it like this? |
I'm happy to do that instead, I'm not sure how to make it happen |
You could try using the skill: https://github.com/InsightSoftwareConsortium/ITK/tree/main/.github/skills/update-third-party |
Thanks I'll take a look |
|
Verified locally: the failure reproduces on GCC 15 / libstdc++ in C++20 mode (CachyOS), not only Fedora 44 — |
|
Closing pending #6515 |
|
#6515 isn't a simple solution sadly. |
|
O, I missed this was targeting ITK 4.14! |
Yup. I have zombie projects I'm performing necromancy on to keep going. |
|
Thanks for keeping these old branches alive, @gdevenyi — the necromancy is appreciated. I'm fine with the change in principle: Which is my larger question: rather than retrofitting C++03-era KWSys for C++20, why not build 4.14 with a C++ standard appropriate to its era? A downstream pinning release-4.14 (minc-toolkit-v2, Convert3D, …) can just pin If the goal really is "compile clean in C++20 mode," then I agree with @dzenanz that refreshing KWSys from upstream (#6515) is the right long-term fix rather than a local patch — though I see that turned out to be non-trivial. |
Thanks @hjmjohnson I was able to implement this and get things working that way. |
Problem
std::allocator::rebindwas deprecated in C++17 and removed in C++20. On newer toolchains (e.g. GCC 14/15 shipping in Fedora 44) libstdc++ no longer providesstd::allocator<T>::rebind, so the vendored KWSyshashtable.hxxtemplate fails to compile:This breaks any consumer that pulls in
itksys/hash_map.hxx/hash_set.hxxwhen built in C++20 mode.Fix
Replace the three
typename _Alloc::template rebind<X>::othertypedefs inModules/ThirdParty/KWSys/src/KWSys/hashtable.hxx.inwith the standard C++11 replacement:std::allocator_traitshas been the portable way to rebind since C++11 and works across C++11 → C++20.<memory>is already included by this header, so no new include is needed. No behavior change on older standards.Only
hashtable.hxx.inusesrebind;hash_map.hxx.in/hash_set.hxx.inare unaffected.Notes
release-4.14directly since that branch is pinned by downstream consumers (e.g. minc-toolkit-v2) and currently fails on Fedora 44.🤖 Generated with Claude Code