Title
Precondition of (not replaced) operator delete[]
Status
nad
Section
[new.delete.array]
Submitter
blacktea hamburger

Created on 2022-09-25.00:00:00 last changed 17 months ago

Messages

Date: 2022-11-30.17:59:24

Proposed resolution:

This wording is relative to N4917.

  1. 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), or operator 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[].

    […]

Date: 2022-11-30.00:00:00

[ 2022-11-30 LWG telecon. Status changed: Tentatively NAD → NAD. ]

Date: 2022-10-15.00:00:00

[ 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)."

Date: 2022-09-25.00:00:00

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:24adminsetmessages: + msg13142
2022-10-12 14:38:02adminsetmessages: + msg12848
2022-10-12 14:38:02adminsetstatus: new -> nad
2022-09-25 18:21:35adminsetmessages: + msg12820
2022-09-25 00:00:00admincreate