When I added the std::allocator_traits<std::allocator<void>>
specialization it broke code like this:
std::allocate_shared<const int>(std::allocator<void>());
The problem is that allocator_traits<allocator<void>>::construct(a, p)
now uses std::_Construct(p), which only does a static_cast<void*>(p) and
so fails if the pointer has cv-quals.
This changes std::_Construct (and the related std::_Construct_novalue)
to use a C-style cast to (void*) which matches the effects of the
"voidify" helper in the C++20 standard.
libstdc++-v3/ChangeLog:
* include/bits/stl_construct.h (_Construct, _Construct_novalue):
Also cast away cv-qualifiers when converting pointer to void.
* testsuite/20_util/allocator/void.cc: Test construct function
with cv-qualified types.
return;
}
#endif
- ::new(static_cast<void*>(__p)) _Tp(std::forward<_Args>(__args)...);
+ ::new((void*)__p) _Tp(std::forward<_Args>(__args)...);
}
#else
template<typename _T1, typename _T2>
template<typename _T1>
inline void
_Construct_novalue(_T1* __p)
- { ::new(static_cast<void*>(__p)) _T1; }
+ { ::new((void*)__p) _T1; }
template<typename _ForwardIterator>
_GLIBCXX20_CONSTEXPR void
"const_pointer is const void*" );
#endif // C++20
+void
+test02()
+{
+ std::allocator<void> av;
+ int* p = std::allocator<int>().allocate(1);
+ const int* c = p;
+ std::allocator_traits<std::allocator<void>>::construct(av, c, 0);
+ volatile int* v = p;
+ std::allocator_traits<std::allocator<void>>::construct(av, v, 0);
+ const volatile int* cv = p;
+ std::allocator_traits<std::allocator<void>>::construct(av, cv, 0);
+ std::allocator<int>().deallocate(p, 1);
+}
+
int
main()
{
test01();
+ test02();
}