Date: Sun, 24 Aug 2025 17:21:05 +0100
Sent from my Galaxy
-------- Original message --------From: David Brown <david.brown_at_[hidden]> Date: 8/24/25 4:41 PM (GMT+01:00) To: organicoman <organicoman_at_[hidden]>, std-proposals_at_[hidden] Subject: Re: [std-proposals] Delete...why not a parameter by reference?! On 24/08/2025 16:41, organicoman wrote:> > >> That would be nice - if it had the slightest influence on the issue,>> which it does not.> >> If you use "delete p;", and then try to dereference p, then the>> behaviour is undefined. /Anything/ can happen - including launching>> nasal daemons, or crashing the program, or deleting your files, or>> coincidentally doing something useful. It does not matter if "p" is>> assigned to nullptr, left unchanged, or has a random value - the>> behaviour is still undefined.> > Yes true, but atleast you can check if a delete was called on your > pointer, then you can do this:> > if (m_ptr) // if false then definitely deleted.> Anyone who is able to check their pointers before use, is equally able to assign 0 to deleted pointers.{ T* p = new T; Dll_fn_takes_by_Copy (p); delete p;}Show me how.A language change only helps people avoid mistakes if it does so automatically or with significantly greater convenience than they already have. Your suggestion only helps people who are careful in their coding, and those people are already careful and don't make the mistakes that your change could prevent.If you want to help less careful programmers avoid mistakes, campaign for std::unique_ptr and friends to have validity checking on dereference, throwing exceptions on null pointers. (The campaign wouldn't work because people don't want that extra overhead.)I understand why everyone is on the defensive, and I agree totally that we should not obstruct the smart pointer campaign.But library implemented and low level will definitely use raw pointers....just show me how many std::vector implementation uses smart pointers for its internal data pointer.
-------- Original message --------From: David Brown <david.brown_at_[hidden]> Date: 8/24/25 4:41 PM (GMT+01:00) To: organicoman <organicoman_at_[hidden]>, std-proposals_at_[hidden] Subject: Re: [std-proposals] Delete...why not a parameter by reference?! On 24/08/2025 16:41, organicoman wrote:> > >> That would be nice - if it had the slightest influence on the issue,>> which it does not.> >> If you use "delete p;", and then try to dereference p, then the>> behaviour is undefined. /Anything/ can happen - including launching>> nasal daemons, or crashing the program, or deleting your files, or>> coincidentally doing something useful. It does not matter if "p" is>> assigned to nullptr, left unchanged, or has a random value - the>> behaviour is still undefined.> > Yes true, but atleast you can check if a delete was called on your > pointer, then you can do this:> > if (m_ptr) // if false then definitely deleted.> Anyone who is able to check their pointers before use, is equally able to assign 0 to deleted pointers.{ T* p = new T; Dll_fn_takes_by_Copy (p); delete p;}Show me how.A language change only helps people avoid mistakes if it does so automatically or with significantly greater convenience than they already have. Your suggestion only helps people who are careful in their coding, and those people are already careful and don't make the mistakes that your change could prevent.If you want to help less careful programmers avoid mistakes, campaign for std::unique_ptr and friends to have validity checking on dereference, throwing exceptions on null pointers. (The campaign wouldn't work because people don't want that extra overhead.)I understand why everyone is on the defensive, and I agree totally that we should not obstruct the smart pointer campaign.But library implemented and low level will definitely use raw pointers....just show me how many std::vector implementation uses smart pointers for its internal data pointer.
Received on 2025-08-24 16:21:13