[conv.general] (original) (raw)

7 Expressions [expr]

7.3 Standard conversions [conv]

7.3.1 General [conv.general]

Standard conversions are implicit conversions with built-in meaning.

[conv] enumerates the full set of such conversions.

Astandard conversion sequence is a sequence of standard conversions in the following order:

[Note 1:

A standard conversion sequence can be empty, i.e., it can consist of no conversions.

— _end note_]

A standard conversion sequence will be applied to an expression if necessary to convert it to an expression having a required destination type and value category.

[Note 2:

Expressions with a given type will be implicitly converted to other types in several contexts:

— _end note_]

An expression E can beimplicitly converted to a type T if and only if the declaration T t=E; is well-formed, for some invented temporary variable t ([dcl.init]).

Certain language constructs require that an expression be converted to a Boolean value.

An expression E appearing in such a context is said to becontextually converted to bool and is well-formed if and only if the declaration bool t(E); is well-formed, for some invented temporary variable t ([dcl.init]).

Certain language constructs require conversion to a value having one of a specified set of types appropriate to the construct.

An expression E of class type C appearing in such a context is said to becontextually implicitly converted to a specified type T and is well-formed if and only if E can be implicitly converted to a type Tthat is determined as follows:C is searched for non-explicit conversion functions whose return type is cv T or reference to cv T such that T is allowed by the context.

There shall be exactly one such T.

The effect of any implicit conversion is the same as performing the corresponding declaration and initialization and then using the temporary variable as the result of the conversion.

The result is an lvalue if T is an lvalue reference type or an rvalue reference to function type ([dcl.ref]), an xvalue if T is an rvalue reference to object type, and a prvalue otherwise.

The expression Eis used as a glvalue if and only if the initialization uses it as a glvalue.

[Note 3:

For class types, user-defined conversions are considered as well; see [class.conv].

In general, an implicit conversion sequence ([over.best.ics]) consists of a standard conversion sequence followed by a user-defined conversion followed by another standard conversion sequence.

— _end note_]

[Note 4:

There are some contexts where certain conversions are suppressed.

For example, the lvalue-to-rvalue conversion is not done on the operand of the unary & operator.

Specific exceptions are given in the descriptions of those operators and contexts.

— _end note_]