diff --git a/libstdc++-v3/include/bits/stl_construct.h b/libstdc++-v3/include/bits/stl_construct.h index 7c5fd4c9cf7..9531222809c 100644 --- a/libstdc++-v3/include/bits/stl_construct.h +++ b/libstdc++-v3/include/bits/stl_construct.h @@ -116,7 +116,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION return; } #endif - ::new(static_cast(__p)) _Tp(std::forward<_Args>(__args)...); + ::new((void*)__p) _Tp(std::forward<_Args>(__args)...); } #else template @@ -132,7 +132,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template inline void _Construct_novalue(_T1* __p) - { ::new(static_cast(__p)) _T1; } + { ::new((void*)__p) _T1; } template _GLIBCXX20_CONSTEXPR void diff --git a/libstdc++-v3/testsuite/20_util/allocator/void.cc b/libstdc++-v3/testsuite/20_util/allocator/void.cc index 52e1fef3700..5cdf0be012c 100644 --- a/libstdc++-v3/testsuite/20_util/allocator/void.cc +++ b/libstdc++-v3/testsuite/20_util/allocator/void.cc @@ -87,8 +87,23 @@ static_assert( std::is_same::const_pointer, const void*>(), "const_pointer is const void*" ); #endif // C++20 +void +test02() +{ + std::allocator av; + int* p = std::allocator().allocate(1); + const int* c = p; + std::allocator_traits>::construct(av, c, 0); + volatile int* v = p; + std::allocator_traits>::construct(av, v, 0); + const volatile int* cv = p; + std::allocator_traits>::construct(av, cv, 0); + std::allocator().deallocate(p, 1); +} + int main() { test01(); + test02(); }