Consider the following code:
template <typename T> int foo();
template <typename T> int foo() = delete;
is this valid C++11?
... see it all on GodBolt.
so which compilers are right and which compilers are s@#$%e ? :-)
delete is used for one single pointer and delete[] is used for deleting an array through a pointer.
Using the delete operator on an object deallocates its memory.
= delete can be used for any function, in which case it is explicitly marked as deleted and any use results in a compiler error.
Delete is an operator that is used to destroy array and non-array(pointer) objects which are created by new expression. Delete can be used by either using Delete operator or Delete [ ] operator. New operator is used for dynamic memory allocation which puts variables on heap memory.
GCC and MSVC have a bug.
[dcl.fct.def.delete]
4 ... A deleted definition of a function shall be the first declaration of the function or, for an explicit specialization of a function template, the first declaration of that specialization...
Which I believe stands for instantiated declarations and definitions too. Since referring to a deleted function is a hard error, it must be declared as deleted asap.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With