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