tmp/tmp2v2fpqj7/{from.md → to.md}
RENAMED
|
@@ -1,175 +0,0 @@
|
|
| 1 |
-
### General <a id="expr.prim.general">[[expr.prim.general]]</a>
|
| 2 |
-
|
| 3 |
-
``` bnf
|
| 4 |
-
primary-expression:
|
| 5 |
-
literal
|
| 6 |
-
'this'
|
| 7 |
-
'(' expression ')'
|
| 8 |
-
id-expression
|
| 9 |
-
lambda-expression
|
| 10 |
-
```
|
| 11 |
-
|
| 12 |
-
``` bnf
|
| 13 |
-
id-expression:
|
| 14 |
-
unqualified-id
|
| 15 |
-
qualified-id
|
| 16 |
-
```
|
| 17 |
-
|
| 18 |
-
``` bnf
|
| 19 |
-
unqualified-id:
|
| 20 |
-
identifier
|
| 21 |
-
operator-function-id
|
| 22 |
-
conversion-function-id
|
| 23 |
-
literal-operator-id
|
| 24 |
-
'~' class-name
|
| 25 |
-
'~' decltype-specifier
|
| 26 |
-
template-id
|
| 27 |
-
```
|
| 28 |
-
|
| 29 |
-
A *literal* is a primary expression. Its type depends on its form (
|
| 30 |
-
[[lex.literal]]). A string literal is an lvalue; all other literals are
|
| 31 |
-
prvalues.
|
| 32 |
-
|
| 33 |
-
The keyword `this` names a pointer to the object for which a non-static
|
| 34 |
-
member function ([[class.this]]) is invoked or a non-static data
|
| 35 |
-
member’s initializer ([[class.mem]]) is evaluated.
|
| 36 |
-
|
| 37 |
-
If a declaration declares a member function or member function template
|
| 38 |
-
of a class `X`, the expression `this` is a prvalue of type “pointer to
|
| 39 |
-
*cv-qualifier-seq* `X`” between the optional *cv-qualifer-seq* and the
|
| 40 |
-
end of the *function-definition*, *member-declarator*, or *declarator*.
|
| 41 |
-
It shall not appear before the optional *cv-qualifier-seq* and it shall
|
| 42 |
-
not appear within the declaration of a static member function (although
|
| 43 |
-
its type and value category are defined within a static member function
|
| 44 |
-
as they are within a non-static member function). this is because
|
| 45 |
-
declaration matching does not occur until the complete declarator is
|
| 46 |
-
known. Unlike the object expression in other contexts, `*this` is not
|
| 47 |
-
required to be of complete type for purposes of class member access (
|
| 48 |
-
[[expr.ref]]) outside the member function body. only class members
|
| 49 |
-
declared prior to the declaration are visible.
|
| 50 |
-
|
| 51 |
-
``` cpp
|
| 52 |
-
struct A {
|
| 53 |
-
char g();
|
| 54 |
-
template<class T> auto f(T t) -> decltype(t + g())
|
| 55 |
-
{ return t + g(); }
|
| 56 |
-
};
|
| 57 |
-
template auto A::f(int t) -> decltype(t + g());
|
| 58 |
-
```
|
| 59 |
-
|
| 60 |
-
Otherwise, if a *member-declarator* declares a non-static data member (
|
| 61 |
-
[[class.mem]]) of a class `X`, the expression `this` is a prvalue of
|
| 62 |
-
type “pointer to `X`” within the optional *brace-or-equal-initializer*.
|
| 63 |
-
It shall not appear elsewhere in the *member-declarator*.
|
| 64 |
-
|
| 65 |
-
The expression `this` shall not appear in any other context.
|
| 66 |
-
|
| 67 |
-
``` cpp
|
| 68 |
-
class Outer {
|
| 69 |
-
int a[sizeof(*this)]; // error: not inside a member function
|
| 70 |
-
unsigned int sz = sizeof(*this); // OK: in brace-or-equal-initializer
|
| 71 |
-
|
| 72 |
-
void f() {
|
| 73 |
-
int b[sizeof(*this)]; // OK
|
| 74 |
-
|
| 75 |
-
struct Inner {
|
| 76 |
-
int c[sizeof(*this)]; // error: not inside a member function of Inner
|
| 77 |
-
};
|
| 78 |
-
}
|
| 79 |
-
};
|
| 80 |
-
```
|
| 81 |
-
|
| 82 |
-
A parenthesized expression is a primary expression whose type and value
|
| 83 |
-
are identical to those of the enclosed expression. The presence of
|
| 84 |
-
parentheses does not affect whether the expression is an lvalue. The
|
| 85 |
-
parenthesized expression can be used in exactly the same contexts as
|
| 86 |
-
those where the enclosed expression can be used, and with the same
|
| 87 |
-
meaning, except as otherwise indicated.
|
| 88 |
-
|
| 89 |
-
An *id-expression* is a restricted form of a *primary-expression*. an
|
| 90 |
-
*id-expression* can appear after `.` and `->` operators ([[expr.ref]]).
|
| 91 |
-
|
| 92 |
-
An *identifier* is an *id-expression* provided it has been suitably
|
| 93 |
-
declared (Clause [[dcl.dcl]]). for *operator-function-id*s, see
|
| 94 |
-
[[over.oper]]; for *conversion-function-id*s, see [[class.conv.fct]];
|
| 95 |
-
for *literal-operator-id*s, see [[over.literal]]; for *template-id*s,
|
| 96 |
-
see [[temp.names]]. A *class-name* or *decltype-specifier* prefixed by
|
| 97 |
-
`~` denotes a destructor; see [[class.dtor]]. Within the definition of
|
| 98 |
-
a non-static member function, an *identifier* that names a non-static
|
| 99 |
-
member is transformed to a class member access expression (
|
| 100 |
-
[[class.mfct.non-static]]). The type of the expression is the type of
|
| 101 |
-
the *identifier*. The result is the entity denoted by the identifier.
|
| 102 |
-
The result is an lvalue if the entity is a function, variable, or data
|
| 103 |
-
member and a prvalue otherwise.
|
| 104 |
-
|
| 105 |
-
``` bnf
|
| 106 |
-
qualified-id:
|
| 107 |
-
nested-name-specifier 'template'ₒₚₜ unqualified-id
|
| 108 |
-
```
|
| 109 |
-
|
| 110 |
-
``` bnf
|
| 111 |
-
nested-name-specifier:
|
| 112 |
-
'::'
|
| 113 |
-
type-name '::'
|
| 114 |
-
namespace-name '::'
|
| 115 |
-
decltype-specifier '::'
|
| 116 |
-
nested-name-specifier identifier '::'
|
| 117 |
-
nested-name-specifier 'template'ₒₚₜ simple-template-id '::'
|
| 118 |
-
```
|
| 119 |
-
|
| 120 |
-
The type denoted by a *decltype-specifier* in a *nested-name-specifier*
|
| 121 |
-
shall be a class or enumeration type.
|
| 122 |
-
|
| 123 |
-
A *nested-name-specifier* that denotes a class, optionally followed by
|
| 124 |
-
the keyword `template` ([[temp.names]]), and then followed by the name
|
| 125 |
-
of a member of either that class ([[class.mem]]) or one of its base
|
| 126 |
-
classes (Clause [[class.derived]]), is a *qualified-id*;
|
| 127 |
-
[[class.qual]] describes name lookup for class members that appear in
|
| 128 |
-
*qualified-ids*. The result is the member. The type of the result is the
|
| 129 |
-
type of the member. The result is an lvalue if the member is a static
|
| 130 |
-
member function or a data member and a prvalue otherwise. a class member
|
| 131 |
-
can be referred to using a *qualified-id* at any point in its potential
|
| 132 |
-
scope ([[basic.scope.class]]). Where *class-name* `::~` *class-name* is
|
| 133 |
-
used, the two *class-name*s shall refer to the same class; this notation
|
| 134 |
-
names the destructor ([[class.dtor]]). The form
|
| 135 |
-
`~` *decltype-specifier* also denotes the destructor, but it shall not
|
| 136 |
-
be used as the *unqualified-id* in a *qualified-id*. a *typedef-name*
|
| 137 |
-
that names a class is a *class-name* ([[class.name]]).
|
| 138 |
-
|
| 139 |
-
A `::`, or a *nested-name-specifier* that names a namespace (
|
| 140 |
-
[[basic.namespace]]), in either case followed by the name of a member of
|
| 141 |
-
that namespace (or the name of a member of a namespace made visible by a
|
| 142 |
-
*using-directive*) is a *qualified-id*; [[namespace.qual]] describes
|
| 143 |
-
name lookup for namespace members that appear in *qualified-ids*. The
|
| 144 |
-
result is the member. The type of the result is the type of the member.
|
| 145 |
-
The result is an lvalue if the member is a function or a variable and a
|
| 146 |
-
prvalue otherwise.
|
| 147 |
-
|
| 148 |
-
A *nested-name-specifier* that denotes an enumeration ([[dcl.enum]]),
|
| 149 |
-
followed by the name of an enumerator of that enumeration, is a
|
| 150 |
-
*qualified-id* that refers to the enumerator. The result is the
|
| 151 |
-
enumerator. The type of the result is the type of the enumeration. The
|
| 152 |
-
result is a prvalue.
|
| 153 |
-
|
| 154 |
-
In a *qualified-id*, if the *unqualified-id* is a
|
| 155 |
-
*conversion-function-id*, its *conversion-type-id* shall denote the same
|
| 156 |
-
type in both the context in which the entire *qualified-id* occurs and
|
| 157 |
-
in the context of the class denoted by the *nested-name-specifier*.
|
| 158 |
-
|
| 159 |
-
An *id-expression* that denotes a non-static data member or non-static
|
| 160 |
-
member function of a class can only be used:
|
| 161 |
-
|
| 162 |
-
- as part of a class member access ([[expr.ref]]) in which the object
|
| 163 |
-
expression refers to the member’s class[^4] or a class derived from
|
| 164 |
-
that class, or
|
| 165 |
-
- to form a pointer to member ([[expr.unary.op]]), or
|
| 166 |
-
- if that *id-expression* denotes a non-static data member and it
|
| 167 |
-
appears in an unevaluated operand.
|
| 168 |
-
``` cpp
|
| 169 |
-
struct S {
|
| 170 |
-
int m;
|
| 171 |
-
};
|
| 172 |
-
int i = sizeof(S::m); // OK
|
| 173 |
-
int j = sizeof(S::m + 42); // OK
|
| 174 |
-
```
|
| 175 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|