tmp/tmpiq6nh9m7/{from.md → to.md}
RENAMED
|
@@ -8,29 +8,38 @@ attribute-specifier-seqₒₚₜ decl-specifier-seqₒₚₜ declarator virt-spe
|
|
| 8 |
|
| 9 |
is called a *deleted definition*. A function with a deleted definition
|
| 10 |
is also called a *deleted function*.
|
| 11 |
|
| 12 |
A program that refers to a deleted function implicitly or explicitly,
|
| 13 |
-
other than to declare it, is ill-formed.
|
| 14 |
-
function implicitly or explicitly and forming a pointer or
|
| 15 |
-
pointer-to-member to the function. It applies even for references in
|
| 16 |
-
expressions that are not potentially-evaluated. If a function is
|
| 17 |
-
overloaded, it is referenced only if the function is selected by
|
| 18 |
-
overload resolution.
|
| 19 |
|
| 20 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
initialization with
|
| 22 |
|
| 23 |
``` cpp
|
| 24 |
struct onlydouble {
|
| 25 |
onlydouble() = delete; // OK, but redundant
|
| 26 |
onlydouble(std::intmax_t) = delete;
|
| 27 |
onlydouble(double);
|
| 28 |
};
|
| 29 |
```
|
| 30 |
|
| 31 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
deleted definitions of a user-declared `operator new` for that class.
|
| 33 |
|
| 34 |
``` cpp
|
| 35 |
struct sometype {
|
| 36 |
void* operator new(std::size_t) = delete;
|
|
@@ -38,10 +47,14 @@ struct sometype {
|
|
| 38 |
};
|
| 39 |
sometype* p = new sometype; // error, deleted class operator new
|
| 40 |
sometype* q = new sometype[3]; // error, deleted class operator new[]
|
| 41 |
```
|
| 42 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
One can make a class uncopyable, i.e. move-only, by using deleted
|
| 44 |
definitions of the copy constructor and copy assignment operator, and
|
| 45 |
then providing defaulted definitions of the move constructor and move
|
| 46 |
assignment operator.
|
| 47 |
|
|
@@ -56,18 +69,29 @@ struct moveonly {
|
|
| 56 |
};
|
| 57 |
moveonly* p;
|
| 58 |
moveonly q(*p); // error, deleted copy constructor
|
| 59 |
```
|
| 60 |
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 66 |
|
| 67 |
``` cpp
|
| 68 |
struct sometype {
|
| 69 |
sometype();
|
| 70 |
};
|
| 71 |
sometype::sometype() = delete; // ill-formed; not first declaration
|
| 72 |
```
|
| 73 |
|
|
|
|
|
|
|
|
|
| 8 |
|
| 9 |
is called a *deleted definition*. A function with a deleted definition
|
| 10 |
is also called a *deleted function*.
|
| 11 |
|
| 12 |
A program that refers to a deleted function implicitly or explicitly,
|
| 13 |
+
other than to declare it, is ill-formed.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
+
[*Note 1*: This includes calling the function implicitly or explicitly
|
| 16 |
+
and forming a pointer or pointer-to-member to the function. It applies
|
| 17 |
+
even for references in expressions that are not potentially-evaluated.
|
| 18 |
+
If a function is overloaded, it is referenced only if the function is
|
| 19 |
+
selected by overload resolution. The implicit odr-use (
|
| 20 |
+
[[basic.def.odr]]) of a virtual function does not, by itself, constitute
|
| 21 |
+
a reference. — *end note*]
|
| 22 |
+
|
| 23 |
+
[*Example 1*:
|
| 24 |
+
|
| 25 |
+
One can enforce non-default-initialization and non-integral
|
| 26 |
initialization with
|
| 27 |
|
| 28 |
``` cpp
|
| 29 |
struct onlydouble {
|
| 30 |
onlydouble() = delete; // OK, but redundant
|
| 31 |
onlydouble(std::intmax_t) = delete;
|
| 32 |
onlydouble(double);
|
| 33 |
};
|
| 34 |
```
|
| 35 |
|
| 36 |
+
— *end example*]
|
| 37 |
+
|
| 38 |
+
[*Example 2*:
|
| 39 |
+
|
| 40 |
+
One can prevent use of a class in certain *new-expression*s by using
|
| 41 |
deleted definitions of a user-declared `operator new` for that class.
|
| 42 |
|
| 43 |
``` cpp
|
| 44 |
struct sometype {
|
| 45 |
void* operator new(std::size_t) = delete;
|
|
|
|
| 47 |
};
|
| 48 |
sometype* p = new sometype; // error, deleted class operator new
|
| 49 |
sometype* q = new sometype[3]; // error, deleted class operator new[]
|
| 50 |
```
|
| 51 |
|
| 52 |
+
— *end example*]
|
| 53 |
+
|
| 54 |
+
[*Example 3*:
|
| 55 |
+
|
| 56 |
One can make a class uncopyable, i.e. move-only, by using deleted
|
| 57 |
definitions of the copy constructor and copy assignment operator, and
|
| 58 |
then providing defaulted definitions of the move constructor and move
|
| 59 |
assignment operator.
|
| 60 |
|
|
|
|
| 69 |
};
|
| 70 |
moveonly* p;
|
| 71 |
moveonly q(*p); // error, deleted copy constructor
|
| 72 |
```
|
| 73 |
|
| 74 |
+
— *end example*]
|
| 75 |
+
|
| 76 |
+
A deleted function is implicitly an inline function ([[dcl.inline]]).
|
| 77 |
+
|
| 78 |
+
[*Note 2*: The one-definition rule ([[basic.def.odr]]) applies to
|
| 79 |
+
deleted definitions. — *end note*]
|
| 80 |
+
|
| 81 |
+
A deleted definition of a function shall be the first declaration of the
|
| 82 |
+
function or, for an explicit specialization of a function template, the
|
| 83 |
+
first declaration of that specialization. An implicitly declared
|
| 84 |
+
allocation or deallocation function ([[basic.stc.dynamic]]) shall not
|
| 85 |
+
be defined as deleted.
|
| 86 |
+
|
| 87 |
+
[*Example 4*:
|
| 88 |
|
| 89 |
``` cpp
|
| 90 |
struct sometype {
|
| 91 |
sometype();
|
| 92 |
};
|
| 93 |
sometype::sometype() = delete; // ill-formed; not first declaration
|
| 94 |
```
|
| 95 |
|
| 96 |
+
— *end example*]
|
| 97 |
+
|