https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108951

--- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> ---
--- a/libstdc++-v3/include/bits/valarray_array.h
+++ b/libstdc++-v3/include/bits/valarray_array.h
@@ -54,15 +54,41 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
     _Tp*
     __valarray_get_storage(size_t) __attribute__((__malloc__));

+#if __has_builtin(__builtin_operator_new) >= 201802L
+# define _GLIBCXX_OPERATOR_NEW __builtin_operator_new
+# define _GLIBCXX_OPERATOR_DELETE __builtin_operator_delete
+#else
+# define _GLIBCXX_OPERATOR_NEW ::operator new
+# define _GLIBCXX_OPERATOR_DELETE ::operator delete
+#endif
+
   template<typename _Tp>
     inline _Tp*
     __valarray_get_storage(size_t __n)
-    { return static_cast<_Tp*>(operator new(__n * sizeof(_Tp))); }
+    {
+#if __cpp_aligned_new && __cplusplus >= 201103L
+      if (alignof(_Tp) > __STDCPP_DEFAULT_NEW_ALIGNMENT__)
+       return (_Tp*) _GLIBCXX_OPERATOR_NEW(__n * sizeof(_Tp),
+                                           align_val_t(alignof(_Tp)));
+#endif
+      return (_Tp*) _GLIBCXX_OPERATOR_NEW(__n * sizeof(_Tp));
+    }

   // Return memory to the system
   inline void
   __valarray_release_memory(void* __p)
-  { operator delete(__p); }
+  {
+#if __cpp_aligned_new && __cplusplus >= 201103L
+       if (alignof(_Tp) > __STDCPP_DEFAULT_NEW_ALIGNMENT__)
+         {
+           _GLIBCXX_OPERATOR_DELETE(__p, align_val_t(alignof(_Tp)));
+           return;
+         }
+#endif
+       _GLIBCXX_OPERATOR_DELETE(__p);
+  }
+#undef _GLIBCXX_OPERATOR_DELETE
+#undef _GLIBCXX_OPERATOR_NEW

 #pragma GCC diagnostic push
 #pragma GCC diagnostic ignored "-Wc++17-extensions" // if constexpr

Reply via email to