[expr.unary.op] (original) (raw)

7 Expressions [expr]

7.6 Compound expressions [expr.compound]

7.6.2 Unary expressions [expr.unary]

7.6.2.2 Unary operators [expr.unary.op]

The unary * operator performs indirection.

Its operand shall be a prvalue of type “pointer to T”, where T is an object or function type.

The operator yields an lvalue of type T.

If the operand points to an object or function, the result denotes that object or function; otherwise, the behavior is undefined except as specified in [expr.typeid].

[Note 1:

Indirection through a pointer to an incomplete type (other thancv void) is valid.

The lvalue thus obtained can be used in limited ways (to initialize a reference, for example); this lvalue must not be converted to a prvalue, see [conv.lval].

— _end note_]

Each of the following unary operators yields a prvalue.

The operand of the unary & operator shall be an lvalue of some type T.

[Example 1: struct A { int i; };struct B : A { };... &B::i ... int a;int* p1 = &a;int* p2 = p1 + 1; bool b = p2 > p1; — _end example_]

[Note 3:

A pointer to member formed from a mutable non-static data member ([dcl.stc]) does not reflect the mutable specifier associated with the non-static data member.

— _end note_]

A pointer to member is only formed when an explicit & is used and its operand is a qualified-id not enclosed in parentheses.

[Note 4:

That is, the expression &(qualified-id), where thequalified-id is enclosed in parentheses, does not form an expression of type “pointer to member”.

Neither doesqualified-id, because there is no implicit conversion from aqualified-id for a non-static member function to the type “pointer to member function” as there is from an lvalue of function type to the type “pointer to function” ([conv.func]).

Nor is&unqualified-id a pointer to member, even within the scope of the unqualified-id's class.

— _end note_]

If & is applied to an lvalue of incomplete class type and the complete type declares operator&(), it is unspecified whether the operator has the built-in meaning or the operator function is called.

The operand of & shall not be a bit-field.

[Note 5:

The address of an overload set ([over]) can be taken only in a context that uniquely determines which function is referred to (see [over.over]).

Since the context can affect whether the operand is a static or non-static member function, the context can also affect whether the expression has type “pointer to function” or “pointer to member function”.

— _end note_]

The operand of the unary + operator shall be a prvalue of arithmetic, unscoped enumeration, or pointer type and the result is the value of the argument.

Integral promotion is performed on integral or enumeration operands.

The type of the result is the type of the promoted operand.

The operand of the unary - operator shall be a prvalue of arithmetic or unscoped enumeration type and the result is the negative of its operand.

Integral promotion is performed on integral or enumeration operands.

The negative of an unsigned quantity is computed by subtracting its value from , where n is the number of bits in the promoted operand.

The type of the result is the type of the promoted operand.

[Note 6:

The result is the two's complement of the operand (where operand and result are considered as unsigned).

— _end note_]

The operand of the logical negation operator ! is contextually converted to bool ([conv]); its value is trueif the converted operand is false and false otherwise.

The type of the result is bool.

The operand of the ~ operator shall be a prvalue of integral or unscoped enumeration type.

Integral promotions are performed.

The type of the result is the type of the promoted operand.

Given the coefficients of the base-2 representation ([basic.fundamental]) of the promoted operand x, the coefficient of the base-2 representation of the result ris 1 if is 0, and 0 otherwise.

[Note 7:

The result is the ones' complement of the operand (where operand and result are considered as unsigned).

— _end note_]

The ambiguity is resolved by treating ~ as the operator rather than as the start of an unqualified-idnaming a destructor.

[Note 8:

Because the grammar does not permit an operator to follow the., ->, or ​::​ tokens, a ~ followed by a type-name or computed-type-specifier in a member access expression or qualified-id is unambiguously parsed as a destructor name.

— _end note_]