Created on 2022-09-25.00:00:00 last changed 24 months ago
Proposed resolution:
This wording is relative to N4917.
Modify [new.delete.array] as indicated:
void operator delete[](void* ptr) noexcept; void operator delete[](void* ptr, std::size_t size) noexcept; void operator delete[](void* ptr, std::align_val_t alignment) noexcept; void operator delete[](void* ptr, std::size_t size, std::align_val_t alignment) noexcept;-9- Preconditions: ptr is a null pointer or its value represents the address of a block of memory allocated by an earlier call to a (possibly replaced) operator new[](std::size_t),
[…]oroperator new[](std::size_t, std::align_val_t), (not replaced) operator new(std::size_t), or operator new(std::size_t, std::align_val_t) which has not been invalidated by an intervening call to operator delete[].
[ 2022-11-30 LWG telecon. Status changed: Tentatively NAD → NAD. ]
[ 2022-10-10; Reflector poll ]
Set status to "Tentatively NAD" after reflector poll.
"No reason to carve out an exception covering a case on something which can’t be observed by the program (whether the allocation operators are replaced). This just makes things more complicated for no good reason." "This would require changes to sanitizers and other dynamic analyzers, for zero practical benefit (except allowing bad code to go un-diagnosed)."
Consider (operator delete[](std::size_t) and operator new(std::size_t) is not replaced):
operator delete[](operator new(1));
(even not replaced) void* operator new(std::size_t) does not return void* operator new[](std::size_t). So the behavior is undefined according to [new.delete.array] paragraph 9:
Preconditions: ptr is a null pointer or its value represents the address of a block of memory allocated by an earlier call to a (possibly replaced) operator new[](std::size_t) or operator new[](std::size_t, std::align_val_t) which has not been invalidated by an intervening call to operator delete[].
However, consider (operator delete(std::size_t) and operator new[](std::size_t) is not replaced):
operator delete(operator new[](1));
(not replaced) operator new[](std::size_t) simply returns operator new(std::size_t) according to [new.delete.array] paragraph 4:
Default behavior: Returns operator new(size), or operator new(size, alignment), respectively.
So it is well-formed according to [new.delete.single] paragraph 10:
Preconditions: ptr is a null pointer or its value represents the address of a block of memory allocated by an earlier call to a (possibly replaced) operator new(std::size_t) or operator new(std::size_t, std::align_val_t) which has not been invalidated by an intervening call to operator delete.
The behavior should be consistent.
History | |||
---|---|---|---|
Date | User | Action | Args |
2022-11-30 17:59:24 | admin | set | messages: + msg13142 |
2022-10-12 14:38:02 | admin | set | messages: + msg12848 |
2022-10-12 14:38:02 | admin | set | status: new -> nad |
2022-09-25 18:21:35 | admin | set | messages: + msg12820 |
2022-09-25 00:00:00 | admin | create |