tmp/tmpbdsk47av/{from.md → to.md}
RENAMED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
-
### References <a id="dcl.ref">[[dcl.ref]]</a>
|
| 2 |
|
| 3 |
In a declaration `T` `D` where `D` has either of the forms
|
| 4 |
|
| 5 |
``` bnf
|
| 6 |
'&' attribute-specifier-seqₒₚₜ 'D1'
|
|
@@ -11,18 +11,18 @@ and the type of the identifier in the declaration `T` `D1` is
|
|
| 11 |
“*derived-declarator-type-list* `T`”, then the type of the identifier of
|
| 12 |
`D` is “*derived-declarator-type-list* reference to `T`”. The optional
|
| 13 |
*attribute-specifier-seq* appertains to the reference type. Cv-qualified
|
| 14 |
references are ill-formed except when the cv-qualifiers are introduced
|
| 15 |
through the use of a *typedef-name* ([[dcl.typedef]], [[temp.param]])
|
| 16 |
-
or *decltype-specifier*
|
| 17 |
cv-qualifiers are ignored.
|
| 18 |
|
| 19 |
[*Example 1*:
|
| 20 |
|
| 21 |
``` cpp
|
| 22 |
typedef int& A;
|
| 23 |
-
const A aref = 3; //
|
| 24 |
```
|
| 25 |
|
| 26 |
The type of `aref` is “lvalue reference to `int`”, not “lvalue reference
|
| 27 |
to `const int`”.
|
| 28 |
|
|
@@ -86,19 +86,19 @@ void k() {
|
|
| 86 |
declares `p` to be a reference to a pointer to `link` so `h(q)` will
|
| 87 |
leave `q` with the value zero. See also [[dcl.init.ref]].
|
| 88 |
|
| 89 |
— *end example*]
|
| 90 |
|
| 91 |
-
It is unspecified whether or not a reference requires storage
|
| 92 |
-
[[basic.stc]]
|
| 93 |
|
| 94 |
There shall be no references to references, no arrays of references, and
|
| 95 |
no pointers to references. The declaration of a reference shall contain
|
| 96 |
-
an *initializer*
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
declaration of a parameter or a return type
|
| 100 |
[[basic.def]]. A reference shall be initialized to refer to a valid
|
| 101 |
object or function.
|
| 102 |
|
| 103 |
[*Note 2*: In particular, a null reference cannot exist in a
|
| 104 |
well-defined program, because the only way to create such a reference
|
|
@@ -106,15 +106,14 @@ would be to bind it to the “object” obtained by indirection through a
|
|
| 106 |
null pointer, which causes undefined behavior. As described in
|
| 107 |
[[class.bit]], a reference cannot be bound directly to a
|
| 108 |
bit-field. — *end note*]
|
| 109 |
|
| 110 |
If a *typedef-name* ([[dcl.typedef]], [[temp.param]]) or a
|
| 111 |
-
*decltype-specifier*
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
type `TR`.
|
| 116 |
|
| 117 |
[*Note 3*: This rule is known as reference collapsing. — *end note*]
|
| 118 |
|
| 119 |
[*Example 3*:
|
| 120 |
|
|
|
|
| 1 |
+
#### References <a id="dcl.ref">[[dcl.ref]]</a>
|
| 2 |
|
| 3 |
In a declaration `T` `D` where `D` has either of the forms
|
| 4 |
|
| 5 |
``` bnf
|
| 6 |
'&' attribute-specifier-seqₒₚₜ 'D1'
|
|
|
|
| 11 |
“*derived-declarator-type-list* `T`”, then the type of the identifier of
|
| 12 |
`D` is “*derived-declarator-type-list* reference to `T`”. The optional
|
| 13 |
*attribute-specifier-seq* appertains to the reference type. Cv-qualified
|
| 14 |
references are ill-formed except when the cv-qualifiers are introduced
|
| 15 |
through the use of a *typedef-name* ([[dcl.typedef]], [[temp.param]])
|
| 16 |
+
or *decltype-specifier* [[dcl.type.simple]], in which case the
|
| 17 |
cv-qualifiers are ignored.
|
| 18 |
|
| 19 |
[*Example 1*:
|
| 20 |
|
| 21 |
``` cpp
|
| 22 |
typedef int& A;
|
| 23 |
+
const A aref = 3; // error: lvalue reference to non-const initialized with rvalue
|
| 24 |
```
|
| 25 |
|
| 26 |
The type of `aref` is “lvalue reference to `int`”, not “lvalue reference
|
| 27 |
to `const int`”.
|
| 28 |
|
|
|
|
| 86 |
declares `p` to be a reference to a pointer to `link` so `h(q)` will
|
| 87 |
leave `q` with the value zero. See also [[dcl.init.ref]].
|
| 88 |
|
| 89 |
— *end example*]
|
| 90 |
|
| 91 |
+
It is unspecified whether or not a reference requires storage
|
| 92 |
+
[[basic.stc]].
|
| 93 |
|
| 94 |
There shall be no references to references, no arrays of references, and
|
| 95 |
no pointers to references. The declaration of a reference shall contain
|
| 96 |
+
an *initializer* [[dcl.init.ref]] except when the declaration contains
|
| 97 |
+
an explicit `extern` specifier [[dcl.stc]], is a class member
|
| 98 |
+
[[class.mem]] declaration within a class definition, or is the
|
| 99 |
+
declaration of a parameter or a return type [[dcl.fct]]; see
|
| 100 |
[[basic.def]]. A reference shall be initialized to refer to a valid
|
| 101 |
object or function.
|
| 102 |
|
| 103 |
[*Note 2*: In particular, a null reference cannot exist in a
|
| 104 |
well-defined program, because the only way to create such a reference
|
|
|
|
| 106 |
null pointer, which causes undefined behavior. As described in
|
| 107 |
[[class.bit]], a reference cannot be bound directly to a
|
| 108 |
bit-field. — *end note*]
|
| 109 |
|
| 110 |
If a *typedef-name* ([[dcl.typedef]], [[temp.param]]) or a
|
| 111 |
+
*decltype-specifier* [[dcl.type.simple]] denotes a type `TR` that is a
|
| 112 |
+
reference to a type `T`, an attempt to create the type “lvalue reference
|
| 113 |
+
to cv `TR`” creates the type “lvalue reference to `T`”, while an attempt
|
| 114 |
+
to create the type “rvalue reference to cv `TR`” creates the type `TR`.
|
|
|
|
| 115 |
|
| 116 |
[*Note 3*: This rule is known as reference collapsing. — *end note*]
|
| 117 |
|
| 118 |
[*Example 3*:
|
| 119 |
|