8 Declarators [dcl.decl]

8.4 Function definitions [dcl.fct.def]

8.4.3 Deleted definitions [dcl.fct.def.delete]

A function definition of the form:

attribute-specifier-seqopt decl-specifier-seqopt declarator  = delete ;

is called a deleted definition. A function with a deleted definition is also called a deleted function.

A program that refers to a deleted function implicitly or explicitly, other than to declare it, is ill-formed. [ Note: This includes calling the function implicitly or explicitly and forming a pointer or pointer-to-member to the function. It applies even for references in expressions that are not potentially-evaluated. If a function is overloaded, it is referenced only if the function is selected by overload resolution.  — end note ]

Example: One can enforce non-default initialization and non-integral initialization with

struct onlydouble {
  onlydouble() = delete;              // OK, but redundant
  onlydouble(std::intmax_t) = delete;
  onlydouble(double);
};

 — end example ]

Example: One can prevent use of a class in certain new expressions by using deleted definitions of a user-declared operator new for that class.

struct sometype {
  void *operator new(std::size_t) = delete;
  void *operator new[](std::size_t) = delete;
};
sometype *p = new sometype;     // error, deleted class operator new
sometype *q = new sometype[3];  // error, deleted class operator new[]

 — end example ]

Example: One can make a class uncopyable, i.e. move-only, by using deleted definitions of the copy constructor and copy assignment operator, and then providing defaulted definitions of the move constructor and move assignment operator.

struct moveonly {
  moveonly() = default;
  moveonly(const moveonly&) = delete;
  moveonly(moveonly&&) = default;
  moveonly& operator=(const moveonly&) = delete;
  moveonly& operator=(moveonly&&) = default;
  ~moveonly() = default;
};
moveonly *p;
moveonly q(*p); // error, deleted copy constructor

 — end example ]

A deleted function is implicitly inline. [ Note: The one-definition rule ([basic.def.odr]) applies to deleted definitions.  — end note ] 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. [ Example:

struct sometype {
  sometype();
};
sometype::sometype() = delete;      // ill-formed; not first declaration

 — end example ]