[conv.general] # 7 Expressions [[expr]](./#expr) ## 7.3 Standard conversions [[conv]](conv#general) ### 7.3.1 General [conv.general] [1](#1) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/expressions.tex#L503) Standard conversions are implicit conversions with built-in meaning[.](#1.sentence-1) [[conv]](conv "7.3 Standard conversions") enumerates the full set of such conversions[.](#1.sentence-2) A[*standard conversion sequence*](#def:conversion_sequence,standard "7.3.1 General [conv.general]") is a sequence of standard conversions in the following order: - [(1.1)](#1.1) Zero or one conversion from the following set: lvalue-to-rvalue conversion, array-to-pointer conversion, and function-to-pointer conversion[.](#1.1.sentence-1) - [(1.2)](#1.2) Zero or one conversion from the following set: integral promotions, floating-point promotion, integral conversions, floating-point conversions, floating-integral conversions, pointer conversions, pointer-to-member conversions, and boolean conversions[.](#1.2.sentence-1) - [(1.3)](#1.3) Zero or one function pointer conversion[.](#1.3.sentence-1) - [(1.4)](#1.4) Zero or one qualification conversion[.](#1.4.sentence-1) [*Note [1](#note-1)*: A standard conversion sequence can be empty, i.e., it can consist of no conversions[.](#1.sentence-4) — *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[.](#1.sentence-5) [2](#2) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/expressions.tex#L533) [*Note [2](#note-2)*: Expressions with a given type will be implicitly converted to other types in several contexts: - [(2.1)](#2.1) When used as operands of operators[.](#2.1.sentence-1) The operator's requirements for its operands dictate the destination type ([[expr.compound]](expr.compound "7.6 Compound expressions"))[.](#2.1.sentence-2) - [(2.2)](#2.2) When used in the condition of an if statement ([[stmt.if]](stmt.if "8.5.2 The if statement")) or iteration statement ([[stmt.iter]](stmt.iter "8.6 Iteration statements"))[.](#2.2.sentence-1) The destination type isbool[.](#2.2.sentence-2) - [(2.3)](#2.3) When used in the expression of a switch statement ([[stmt.switch]](stmt.switch "8.5.3 The switch statement"))[.](#2.3.sentence-1) The destination type is integral[.](#2.3.sentence-2) - [(2.4)](#2.4) When used as the source expression for an initialization (which includes use as an argument in a function call and use as the expression in a return statement)[.](#2.4.sentence-1) The type of the entity being initialized is (generally) the destination type[.](#2.4.sentence-2) See [[dcl.init]](dcl.init "9.5 Initializers"), [[dcl.init.ref]](dcl.init.ref "9.5.4 References")[.](#2.4.sentence-3) — *end note*] [3](#3) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/expressions.tex#L556) An expression E can be[*implicitly converted*](#def:conversion,implicit "7.3.1 General [conv.general]") to a type T if and only if the declaration T t = E; is well-formed, for some invented temporary variable t ([[dcl.init]](dcl.init "9.5 Initializers"))[.](#3.sentence-1) [4](#4) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/expressions.tex#L562) Certain language constructs require that an expression be converted to a Boolean value[.](#4.sentence-1) An expression E appearing in such a context is said to be[*contextually converted to bool*](#def:conversion,contextual_to_bool "7.3.1 General [conv.general]") and is well-formed if and only if the declaration bool t(E); is well-formed, for some invented temporary variable t ([[dcl.init]](dcl.init "9.5 Initializers"))[.](#4.sentence-2) [5](#5) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/expressions.tex#L569) Certain language constructs require conversion to a value having one of a specified set of types appropriate to the construct[.](#5.sentence-1) An expression E of class type C appearing in such a context is said to be[*contextually implicitly converted*](#def:contextually_implicitly_converted "7.3.1 General [conv.general]") to a specified type T and is well-formed if and only if E can be implicitly converted to a type T that is determined as follows:C is searched for non-explicit conversion functions whose return type is cv T or reference to cvT such that T is allowed by the context[.](#5.sentence-2) There shall be exactly one such T[.](#5.sentence-3) [6](#6) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/expressions.tex#L583) 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[.](#6.sentence-1) The result is an lvalue if T is an lvalue reference type or an rvalue reference to function type ([[dcl.ref]](dcl.ref "9.3.4.3 References")), an xvalue if T is an rvalue reference to object type, and a prvalue otherwise[.](#6.sentence-2) The expression E is used as a glvalue if and only if the initialization uses it as a glvalue[.](#6.sentence-3) [7](#7) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/expressions.tex#L593) [*Note [3](#note-3)*: For class types, user-defined conversions are considered as well; see [[class.conv]](class.conv "11.4.8 Conversions")[.](#7.sentence-1) In general, an implicit conversion sequence ([[over.best.ics]](over.best.ics "12.2.4.2 Implicit conversion sequences")) consists of a standard conversion sequence followed by a user-defined conversion followed by another standard conversion sequence[.](#7.sentence-2) — *end note*] [8](#8) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/expressions.tex#L602) [*Note [4](#note-4)*: There are some contexts where certain conversions are suppressed[.](#8.sentence-1) For example, the lvalue-to-rvalue conversion is not done on the operand of the unary & operator[.](#8.sentence-2) Specific exceptions are given in the descriptions of those operators and contexts[.](#8.sentence-3) — *end note*]