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

--- Comment #9 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Do we want something like this as well? (and for malloc_allocator too)

--- a/libstdc++-v3/include/ext/new_allocator.h
+++ b/libstdc++-v3/include/ext/new_allocator.h
@@ -130,7 +130,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION

       size_type
       max_size() const _GLIBCXX_USE_NOEXCEPT
-      { return size_t(-1) / sizeof(_Tp); }
+      {
+#if __PTRDIFF_MAX__ < __SIZE_MAX__
+       return size_t(__PTRDIFF_MAX__) / sizeof(_Tp);
+#else
+       return size_t(-1) / sizeof(_Tp);
+#endif
+      }

 #if __cplusplus >= 201103L
       template<typename _Up, typename... _Args>


I added the preprocessor condition because I'm not sure if we can always assume
that ptrdiff_t and size_t are the same width.

Reply via email to