From Jason Turner

[expr.unary.op]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmpy5nh1rdd/{from.md → to.md} +57 -34
tmp/tmpy5nh1rdd/{from.md → to.md} RENAMED
@@ -2,61 +2,79 @@
2
 
3
  The unary `*` operator performs *indirection*: the expression to which
4
  it is applied shall be a pointer to an object type, or a pointer to a
5
  function type and the result is an lvalue referring to the object or
6
  function to which the expression points. If the type of the expression
7
- is “pointer to `T`,” the type of the result is “`T`. indirection
8
- through a pointer to an incomplete type (other than *cv* `void`) is
9
- valid. The lvalue thus obtained can be used in limited ways (to
10
- initialize a reference, for example); this lvalue must not be converted
11
- to a prvalue, see  [[conv.lval]].
 
12
 
13
  The result of each of the following unary operators is a prvalue.
14
 
15
  The result of the unary `&` operator is a pointer to its operand. The
16
  operand shall be an lvalue or a *qualified-id*. If the operand is a
17
- *qualified-id* naming a non-static member `m` of some class `C` with
18
- type `T`, the result has type “pointer to member of class `C` of type
19
- `T`” and is a prvalue designating `C::m`. Otherwise, if the type of the
20
- expression is `T`, the result has type “pointer to `T`” and is a prvalue
21
- that is the address of the designated object ([[intro.memory]]) or a
22
- pointer to the designated function. In particular, the address of an
23
- object of type “cv `T`” is “pointer to cv `T`”, with the same
24
- cv-qualification.
 
 
 
 
 
 
 
 
25
 
26
  ``` cpp
27
  struct A { int i; };
28
  struct B : A { };
29
  ... &B::i ... // has type int A::*
 
 
 
 
30
  ```
31
 
32
- a pointer to member formed from a `mutable` non-static data member (
33
- [[dcl.stc]]) does not reflect the `mutable` specifier associated with
34
- the non-static data member.
 
 
35
 
36
  A pointer to member is only formed when an explicit `&` is used and its
37
- operand is a *qualified-id* not enclosed in parentheses. that is, the
38
- expression `&(qualified-id)`, where the *qualified-id* is enclosed in
39
- parentheses, does not form an expression of type “pointer to member.”
40
- Neither does `qualified-id`, because there is no implicit conversion
41
- from a *qualified-id* for a non-static member function to the type
42
- “pointer to member function” as there is from an lvalue of function type
43
- to the type “pointer to function” ([[conv.func]]). Nor is
44
- `&unqualified-id` a pointer to member, even within the scope of the
45
- *unqualified-id*’s class.
 
46
 
47
  If `&` is applied to an lvalue of incomplete class type and the complete
48
  type declares `operator&()`, it is unspecified whether the operator has
49
  the built-in meaning or the operator function is called. The operand of
50
  `&` shall not be a bit-field.
51
 
52
  The address of an overloaded function (Clause  [[over]]) can be taken
53
  only in a context that uniquely determines which version of the
54
- overloaded function is referred to (see  [[over.over]]). since the
55
- context might determine whether the operand is a static or non-static
56
- member function, the context can also affect whether the expression has
57
- type “pointer to function or “pointer to member function.”
 
 
58
 
59
  The operand of the unary `+` operator shall have arithmetic, unscoped
60
  enumeration, or pointer type and the result is the value of the
61
  argument. Integral promotion is performed on integral or enumeration
62
  operands. The type of the result is the type of the promoted operand.
@@ -72,12 +90,17 @@ The operand of the logical negation operator `!` is contextually
72
  converted to `bool` (Clause  [[conv]]); its value is `true` if the
73
  converted operand is `false` and `false` otherwise. The type of the
74
  result is `bool`.
75
 
76
  The operand of `~` shall have integral or unscoped enumeration type; the
77
- result is the ones complement of its operand. Integral promotions are
78
  performed. The type of the result is the type of the promoted operand.
79
- There is an ambiguity in the *unary-expression* `~X()`, where `X` is a
80
- *class-name* or *decltype-specifier*. The ambiguity is resolved in favor
81
- of treating `~` as a unary complement rather than treating `~X` as
82
- referring to a destructor.
 
 
 
 
 
83
 
 
2
 
3
  The unary `*` operator performs *indirection*: the expression to which
4
  it is applied shall be a pointer to an object type, or a pointer to a
5
  function type and the result is an lvalue referring to the object or
6
  function to which the expression points. If the type of the expression
7
+ is “pointer to `T`”, the type of the result is “`T`”.
8
+
9
+ [*Note 1*: Indirection through a pointer to an incomplete type (other
10
+ than *cv* `void`) is valid. The lvalue thus obtained can be used in
11
+ limited ways (to initialize a reference, for example); this lvalue must
12
+ not be converted to a prvalue, see  [[conv.lval]]. — *end note*]
13
 
14
  The result of each of the following unary operators is a prvalue.
15
 
16
  The result of the unary `&` operator is a pointer to its operand. The
17
  operand shall be an lvalue or a *qualified-id*. If the operand is a
18
+ *qualified-id* naming a non-static or variant member `m` of some class
19
+ `C` with type `T`, the result has type “pointer to member of class `C`
20
+ of type `T`” and is a prvalue designating `C::m`. Otherwise, if the type
21
+ of the expression is `T`, the result has type “pointer to `T`” and is a
22
+ prvalue that is the address of the designated object ([[intro.memory]])
23
+ or a pointer to the designated function.
24
+
25
+ [*Note 2*: In particular, the address of an object of type “cv `T`” is
26
+ “pointer to cv `T`”, with the same cv-qualification. — *end note*]
27
+
28
+ For purposes of pointer arithmetic ([[expr.add]]) and comparison (
29
+ [[expr.rel]], [[expr.eq]]), an object that is not an array element whose
30
+ address is taken in this way is considered to belong to an array with
31
+ one element of type `T`.
32
+
33
+ [*Example 1*:
34
 
35
  ``` cpp
36
  struct A { int i; };
37
  struct B : A { };
38
  ... &B::i ... // has type int A::*
39
+ int a;
40
+ int* p1 = &a;
41
+ int* p2 = p1 + 1; // defined behavior
42
+ bool b = p2 > p1; // defined behavior, with value true
43
  ```
44
 
45
+ *end example*]
46
+
47
+ [*Note 3*: A pointer to member formed from a `mutable` non-static data
48
+ member ([[dcl.stc]]) does not reflect the `mutable` specifier
49
+ associated with the non-static data member. — *end note*]
50
 
51
  A pointer to member is only formed when an explicit `&` is used and its
52
+ operand is a *qualified-id* not enclosed in parentheses.
53
+
54
+ [*Note 4*: That is, the expression `&(qualified-id)`, where the
55
+ *qualified-id* is enclosed in parentheses, does not form an expression
56
+ of type “pointer to member”. Neither does `qualified-id`, because there
57
+ is no implicit conversion from a *qualified-id* for a non-static member
58
+ function to the type “pointer to member function” as there is from an
59
+ lvalue of function type to the type “pointer to function” (
60
+ [[conv.func]]). Nor is `&unqualified-id` a pointer to member, even
61
+ within the scope of the *unqualified-id*’s class. — *end note*]
62
 
63
  If `&` is applied to an lvalue of incomplete class type and the complete
64
  type declares `operator&()`, it is unspecified whether the operator has
65
  the built-in meaning or the operator function is called. The operand of
66
  `&` shall not be a bit-field.
67
 
68
  The address of an overloaded function (Clause  [[over]]) can be taken
69
  only in a context that uniquely determines which version of the
70
+ overloaded function is referred to (see  [[over.over]]).
71
+
72
+ [*Note 5*: Since the context might determine whether the operand is a
73
+ static or non-static member function, the context can also affect
74
+ whether the expression has type “pointer to function” or “pointer to
75
+ member function”. — *end note*]
76
 
77
  The operand of the unary `+` operator shall have arithmetic, unscoped
78
  enumeration, or pointer type and the result is the value of the
79
  argument. Integral promotion is performed on integral or enumeration
80
  operands. The type of the result is the type of the promoted operand.
 
90
  converted to `bool` (Clause  [[conv]]); its value is `true` if the
91
  converted operand is `false` and `false` otherwise. The type of the
92
  result is `bool`.
93
 
94
  The operand of `~` shall have integral or unscoped enumeration type; the
95
+ result is the ones’ complement of its operand. Integral promotions are
96
  performed. The type of the result is the type of the promoted operand.
97
+ There is an ambiguity in the grammar when `~` is followed by a
98
+ *class-name* or *decltype-specifier*. The ambiguity is resolved by
99
+ treating `~` as the unary complement operator rather than as the start
100
+ of an *unqualified-id* naming a destructor.
101
+
102
+ [*Note 6*: Because the grammar does not permit an operator to follow
103
+ the `.`, `->`, or `::` tokens, a `~` followed by a *class-name* or
104
+ *decltype-specifier* in a member access expression or *qualified-id* is
105
+ unambiguously parsed as a destructor name. — *end note*]
106