When you =delete
a function, you actually are deleting its definition.
8.4.3 Deleted definitions [dcl.fct.def.delete]
1 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.
But by doing so, you are also declaring that function. Quoting from the standard [1]:
4 A deleted function is implicitly inline. [ Note: The one-definition rule (3.2) applies to deleted definitions.
—end note ] A deleted definition of a function shall be the first declaration of the function [...]
And so by doing a = A()
, the compiler actually resolves to A::operator=(A&&)
because it has been declared (not A::operator(const A&)
, because A&&
is "more binding" to r-values). However with its definition being deleted, the line is ill-formed.
2 A program that refers to a deleted function implicitly or explicitly, other than to declare it, is ill-formed.
[1] The tone of the emphasized sentence here is actually imperative. The standard directs that declaring a function =delete
d must first appear before other declarations of it. But still, it supports the fact that deleting a function also declares the function.