Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Why are there throw() following the delete[]?

31 views
Skip to first unread message

fl

unread,
Jul 15, 2015, 7:05:44 PM7/15/15
to
Hi,

When I search delete description for C++, I find the following:




ordinary (1)
void operator delete[] (void* ptr) throw();
nothrow (2)
void operator delete[] (void* ptr, const std::nothrow_t& nothrow_constant) throw();
placement (3)
void operator delete[] (void* ptr, void* voidptr2) throw();


The description for the above definitions is:

(1) ordinary delete
Deallocates the memory block pointed to by ptr (if not null), releasing the storage space previously allocated to it by a call to operator new[] and rendering that pointer location invalid.
(2) nothrow delete
Same as above (1).
(3) placement delete
Does nothing.


I am puzzled about:

1. In the normal use of delete[], I never see the throw() following it;
2. The description does not mention about throw() although the upper part
has throw()


Could you explain it to me as I am still a newbie on such a question?


Thanks,

Ian Collins

unread,
Jul 15, 2015, 7:18:40 PM7/15/15
to
fl wrote:
> Hi,
>
> When I search delete description for C++, I find the following:
>
> ordinary (1)
> void operator delete[] (void* ptr) throw();
> nothrow (2)
> void operator delete[] (void* ptr, const std::nothrow_t& nothrow_constant) throw();
> placement (3)
> void operator delete[] (void* ptr, void* voidptr2) throw();
>
<snip>
>
> I am puzzled about:
>
> 1. In the normal use of delete[], I never see the throw() following it;
> 2. The description does not mention about throw() although the upper part
> has throw()

These describe the operators as defined in <new>. The throw() (noexcept
in modern C++) is telling you that the operators will not throw.

You don't include the throw() when you use operator delete, it is only
appropriate in the declaration.


--
Ian Collins

fl

unread,
Jul 15, 2015, 7:36:24 PM7/15/15
to
Thanks. As you said, it is a declaration. Good.
As I am a newbie to C++, I still feel it is different from a normal
declaration. What role of the throw() in the declaration?
I hope your further explanation can teach me more on this.
Thanks again.

Ian Collins

unread,
Jul 15, 2015, 7:44:51 PM7/15/15
to
fl wrote:
> On Wednesday, July 15, 2015 at 4:18:40 PM UTC-7, Ian Collins wrote:
>> fl wrote:
>>> Hi,
>>>
>>> When I search delete description for C++, I find the following:
>>>
>>> ordinary (1)
>>> void operator delete[] (void* ptr) throw();
>>> nothrow (2)
>>> void operator delete[] (void* ptr, const std::nothrow_t& nothrow_constant) throw();
>>> placement (3)
>>> void operator delete[] (void* ptr, void* voidptr2) throw();
>>>
>> <snip>
>>>
>>> I am puzzled about:
>>>
>>> 1. In the normal use of delete[], I never see the throw() following it;
>>> 2. The description does not mention about throw() although the upper part
>>> has throw()
>>
>> These describe the operators as defined in <new>. The throw() (noexcept
>> in modern C++) is telling you that the operators will not throw.
>>
>> You don't include the throw() when you use operator delete, it is only
>> appropriate in the declaration.
>
> Thanks. As you said, it is a declaration. Good.
> As I am a newbie to C++, I still feel it is different from a normal
> declaration. What role of the throw() in the declaration?

As I said above, throw() (noexcept in modern C++) is telling you that
the operators will not throw an exception.

--
Ian Collins

Bo Persson

unread,
Jul 16, 2015, 5:03:20 AM7/16/15
to
On 2015-07-16 01:36, fl wrote:
> On Wednesday, July 15, 2015 at 4:18:40 PM UTC-7, Ian Collins wrote:
>> fl wrote:
>>> Hi,
>>>
>>> When I search delete description for C++, I find the following:
>>>
>>> ordinary (1)
>>> void operator delete[] (void* ptr) throw();
>>> nothrow (2)
>>> void operator delete[] (void* ptr, const std::nothrow_t& nothrow_constant) throw();
>>> placement (3)
>>> void operator delete[] (void* ptr, void* voidptr2) throw();
>>>
>> <snip>
>>>
>>> I am puzzled about:
>>>
>>> 1. In the normal use of delete[], I never see the throw() following it;
>>> 2. The description does not mention about throw() although the upper part
>>> has throw()
>>
>> These describe the operators as defined in <new>. The throw() (noexcept
>> in modern C++) is telling you that the operators will not throw.
>>
>> You don't include the throw() when you use operator delete, it is only
>> appropriate in the declaration.
>>
>>

> Thanks. As you said, it is a declaration. Good.
> As I am a newbie to C++, I still feel it is different from a normal
> declaration. What role of the throw() in the declaration?
> I hope your further explanation can teach me more on this.
>


The throw-part lists the execeptions the function (or operator) is
allowed to throw. Here the list is empty, meaning that it throws no
exceptions.



Bo Persson


0 new messages