On 4/7/20 7:29 AM, Jonathan Wakely wrote:
On Mon, 6 Apr 2020 at 13:45, Nathan Sidwell wrote:
The both operator new and operator delete are looked up in the same
manner. The std does not require a 'matching pair' be found. but it is
extremely poor form for a class to declare exactly one of operator
{new,delete}.
There are unfortunately several such example in the standard!
Pah!
I also realized one could write:
struct Derived : Base {
void *operator new (size_t t) { ... }
using Base::operator delete;
};
which is not such poor code, but the FE will generate calls that
completely lose the usingness of the operator delete.
As RichardB comments, I think the FE needs to mark sets of new/delete
calls for the middle end to safely optimize. but ...
I wonder how much benefit we will really get from trying to make this
optimisation too general.
Just eliding (or coalescing) implicit calls to ::operator new(size_t)
and ::operator delete(void*, size_t) (and the [] and align_val_t forms
of those) probably covers 99% of real cases.
I agree. It's certainly a simpler problem and the major component of
any win we'll get.
nathan
--
Nathan Sidwell