Created on 2015-01-17.00:00:00 last changed 90 months ago
Proposed resolution:
This wording is relative to N4296.
Change [allocator.requirements], Table 28 — "Allocator requirements", as indicated:
Table 28 — Allocator requirements Expression Return type Assertion/note
pre-/post-conditionDefault … a.max_size() X::size_type the largest value that can
meaningfully be passed to
X::allocate()numeric_limits<size_type>::max()/sizeof(value_type) …
Change [allocator.traits.members]/p7 as indicated:
static size_type max_size(const Alloc& a) noexcept;Returns: a.max_size() if that expression is well-formed; otherwise, numeric_limits<size_type>::max()/sizeof(value_type).
[ 2015-05, Lenexa ]
Marshall: Is this the right solution?
PJP: I think it's gilding the lily.
STL: I think this is right, and it doesn't interact with the incomplete container stuff because it's in a member function.
Marshall: Objections to this?
STL: Spaces around binary operators.
Hwrd: It's completely wrong without spaces.
Marshall: All in favor of Ready?
Lots.
Table 28 — "Allocator requirements" says that default behavior for a.max_size() is numeric_limits<size_type>::max(). And this is consistent with the matching statement for allocator_traits in [allocator.traits.members]/p7:
static size_type max_size(const Alloc& a) noexcept;Returns: a.max_size() if that expression is well-formed; otherwise, numeric_limits<size_type>::max().
However, when allocating memory, an allocator must allocate n*sizeof(value_type) bytes, for example:
value_type* allocate(std::size_t n) { return static_cast<value_type*>(::operator new (n * sizeof(value_type))); }
When n == numeric_limits<size_type>::max(), n * sizeof(value_type) is guaranteed to overflow except when sizeof(value_type) == 1.
A more useful default would be numeric_limits<size_type>::max() / sizeof(value_type).History | |||
---|---|---|---|
Date | User | Action | Args |
2017-07-30 20:15:43 | admin | set | status: wp -> c++17 |
2015-10-27 16:52:45 | admin | set | status: ready -> wp |
2015-05-07 23:01:40 | admin | set | messages: + msg7389 |
2015-05-07 23:01:40 | admin | set | status: new -> ready |
2015-01-19 21:36:56 | admin | set | messages: + msg7225 |
2015-01-17 00:00:00 | admin | create |