Init
This commit is contained in:
19
cppdraft/conv/array.md
Normal file
19
cppdraft/conv/array.md
Normal file
@@ -0,0 +1,19 @@
|
||||
[conv.array]
|
||||
|
||||
# 7 Expressions [[expr]](./#expr)
|
||||
|
||||
## 7.3 Standard conversions [[conv]](conv#array)
|
||||
|
||||
### 7.3.3 Array-to-pointer conversion [conv.array]
|
||||
|
||||
[1](#1)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/expressions.tex#L709)
|
||||
|
||||
An lvalue or rvalue of type âarray of N Tâ or âarray
|
||||
of unknown bound of Tâ can be converted to a prvalue of type
|
||||
âpointer to Tâ[.](#1.sentence-1)
|
||||
|
||||
The temporary materialization conversion ([[conv.rval]](conv.rval "7.3.5 Temporary materialization conversion")) is applied[.](#1.sentence-2)
|
||||
|
||||
The result is a pointer to the first element of the array[.](#1.sentence-3)
|
||||
18
cppdraft/conv/bool.md
Normal file
18
cppdraft/conv/bool.md
Normal file
@@ -0,0 +1,18 @@
|
||||
[conv.bool]
|
||||
|
||||
# 7 Expressions [[expr]](./#expr)
|
||||
|
||||
## 7.3 Standard conversions [[conv]](conv#bool)
|
||||
|
||||
### 7.3.15 Boolean conversions [conv.bool]
|
||||
|
||||
[1](#1)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/expressions.tex#L1150)
|
||||
|
||||
A prvalue of arithmetic, unscoped enumeration, pointer, or pointer-to-member
|
||||
type can be converted to a prvalue of type bool[.](#1.sentence-1)
|
||||
|
||||
A zero value, null
|
||||
pointer value, or null member pointer value is converted to false; any
|
||||
other value is converted to true[.](#1.sentence-2)
|
||||
38
cppdraft/conv/double.md
Normal file
38
cppdraft/conv/double.md
Normal file
@@ -0,0 +1,38 @@
|
||||
[conv.double]
|
||||
|
||||
# 7 Expressions [[expr]](./#expr)
|
||||
|
||||
## 7.3 Standard conversions [[conv]](conv#double)
|
||||
|
||||
### 7.3.10 Floating-point conversions [conv.double]
|
||||
|
||||
[1](#1)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/expressions.tex#L967)
|
||||
|
||||
A prvalue of floating-point type can be converted to a prvalue of
|
||||
another floating-point type
|
||||
with a greater or equal conversion rank ([[conv.rank]](conv.rank "6.9.6 Conversion ranks"))[.](#1.sentence-1)
|
||||
|
||||
A prvalue of standard floating-point type can be converted to
|
||||
a prvalue of another standard floating-point type[.](#1.sentence-2)
|
||||
|
||||
[2](#2)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/expressions.tex#L975)
|
||||
|
||||
If the source value can be exactly
|
||||
represented in the destination type, the result of the conversion is
|
||||
that exact representation[.](#2.sentence-1)
|
||||
|
||||
If the source value is between two adjacent
|
||||
destination values, the result of the conversion is animplementation-defined choice of either of those values[.](#2.sentence-2)
|
||||
|
||||
Otherwise, the behavior is undefined[.](#2.sentence-3)
|
||||
|
||||
[3](#3)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/expressions.tex#L983)
|
||||
|
||||
The conversions allowed as floating-point promotions are excluded from
|
||||
the set of floating-point conversions[.](#3.sentence-1)
|
||||
23
cppdraft/conv/fctptr.md
Normal file
23
cppdraft/conv/fctptr.md
Normal file
@@ -0,0 +1,23 @@
|
||||
[conv.fctptr]
|
||||
|
||||
# 7 Expressions [[expr]](./#expr)
|
||||
|
||||
## 7.3 Standard conversions [[conv]](conv#fctptr)
|
||||
|
||||
### 7.3.14 Function pointer conversions [conv.fctptr]
|
||||
|
||||
[1](#1)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/expressions.tex#L1129)
|
||||
|
||||
A prvalue of type âpointer to noexcept functionâ
|
||||
can be converted to a prvalue of type âpointer to functionâ[.](#1.sentence-1)
|
||||
|
||||
The result is a pointer to the function[.](#1.sentence-2)
|
||||
|
||||
A prvalue of type âpointer to member of type noexcept functionâ
|
||||
can be converted to a prvalue of type âpointer to member of type functionâ[.](#1.sentence-3)
|
||||
|
||||
The result designates the member function[.](#1.sentence-4)
|
||||
|
||||
[*Example [1](#example-1)*: void (*p)();void (**pp)() noexcept = &p; // error: cannot convert to pointer to noexcept functionstruct S { typedef void (*p)(); operator p(); };void (*q)() noexcept = S(); // error: cannot convert to pointer to noexcept function â *end example*]
|
||||
53
cppdraft/conv/fpint.md
Normal file
53
cppdraft/conv/fpint.md
Normal file
@@ -0,0 +1,53 @@
|
||||
[conv.fpint]
|
||||
|
||||
# 7 Expressions [[expr]](./#expr)
|
||||
|
||||
## 7.3 Standard conversions [[conv]](conv#fpint)
|
||||
|
||||
### 7.3.11 Floating-integral conversions [conv.fpint]
|
||||
|
||||
[1](#1)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/expressions.tex#L989)
|
||||
|
||||
A prvalue of a floating-point type can be converted to a prvalue of an
|
||||
integer type[.](#1.sentence-1)
|
||||
|
||||
The conversion truncates; that is, the fractional part is
|
||||
discarded[.](#1.sentence-2)
|
||||
|
||||
The behavior is undefined if the truncated value cannot be represented
|
||||
in the destination type[.](#1.sentence-3)
|
||||
|
||||
[*Note [1](#note-1)*:
|
||||
|
||||
If the destination type is bool, see [[conv.bool]](conv.bool "7.3.15 Boolean conversions")[.](#1.sentence-4)
|
||||
|
||||
â *end note*]
|
||||
|
||||
[2](#2)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/expressions.tex#L1001)
|
||||
|
||||
A prvalue of an integer type or of an unscoped enumeration type can be converted to
|
||||
a prvalue of a floating-point type[.](#2.sentence-1)
|
||||
|
||||
The result is exact if possible[.](#2.sentence-2)
|
||||
|
||||
If the value being
|
||||
converted is in the range of values that can be represented but the value cannot be
|
||||
represented exactly, it is an implementation-defined choice of either the next lower or higher representable
|
||||
value[.](#2.sentence-3)
|
||||
|
||||
[*Note [2](#note-2)*:
|
||||
|
||||
Loss of precision occurs if the integral value cannot be represented
|
||||
exactly as a value of the floating-point type[.](#2.sentence-4)
|
||||
|
||||
â *end note*]
|
||||
|
||||
If the value being converted is
|
||||
outside the range of values that can be represented, the behavior is undefined[.](#2.sentence-5)
|
||||
|
||||
If the
|
||||
source type is bool, the value false is converted to zero and the valuetrue is converted to one[.](#2.sentence-6)
|
||||
21
cppdraft/conv/fpprom.md
Normal file
21
cppdraft/conv/fpprom.md
Normal file
@@ -0,0 +1,21 @@
|
||||
[conv.fpprom]
|
||||
|
||||
# 7 Expressions [[expr]](./#expr)
|
||||
|
||||
## 7.3 Standard conversions [[conv]](conv#fpprom)
|
||||
|
||||
### 7.3.8 Floating-point promotion [conv.fpprom]
|
||||
|
||||
[1](#1)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/expressions.tex#L932)
|
||||
|
||||
A prvalue of type float can be converted to a prvalue of typedouble[.](#1.sentence-1)
|
||||
|
||||
The value is unchanged[.](#1.sentence-2)
|
||||
|
||||
[2](#2)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/expressions.tex#L937)
|
||||
|
||||
This conversion is called [*floating-point promotion*](#def:floating-point_promotion "7.3.8 Floating-point promotion [conv.fpprom]")[.](#2.sentence-1)
|
||||
22
cppdraft/conv/func.md
Normal file
22
cppdraft/conv/func.md
Normal file
@@ -0,0 +1,22 @@
|
||||
[conv.func]
|
||||
|
||||
# 7 Expressions [[expr]](./#expr)
|
||||
|
||||
## 7.3 Standard conversions [[conv]](conv#func)
|
||||
|
||||
### 7.3.4 Function-to-pointer conversion [conv.func]
|
||||
|
||||
[1](#1)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/expressions.tex#L721)
|
||||
|
||||
An lvalue of function type T can be converted to a prvalue of
|
||||
type âpointer to Tâ[.](#1.sentence-1)
|
||||
|
||||
The result is a pointer to the
|
||||
function[.](#1.sentence-2)[45](#footnote-45 "This conversion never applies to non-static member functions because an lvalue that refers to a non-static member function cannot be obtained.")
|
||||
|
||||
[45)](#footnote-45)[45)](#footnoteref-45)
|
||||
|
||||
This conversion never applies to non-static member functions because an
|
||||
lvalue that refers to a non-static member function cannot be obtained[.](#footnote-45.sentence-1)
|
||||
169
cppdraft/conv/general.md
Normal file
169
cppdraft/conv/general.md
Normal file
@@ -0,0 +1,169 @@
|
||||
[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*]
|
||||
42
cppdraft/conv/integral.md
Normal file
42
cppdraft/conv/integral.md
Normal file
@@ -0,0 +1,42 @@
|
||||
[conv.integral]
|
||||
|
||||
# 7 Expressions [[expr]](./#expr)
|
||||
|
||||
## 7.3 Standard conversions [[conv]](conv#integral)
|
||||
|
||||
### 7.3.9 Integral conversions [conv.integral]
|
||||
|
||||
[1](#1)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/expressions.tex#L942)
|
||||
|
||||
A prvalue of an integer type can be converted to a prvalue of another
|
||||
integer type[.](#1.sentence-1)
|
||||
|
||||
A prvalue of an unscoped enumeration type can be converted to
|
||||
a prvalue of an integer type[.](#1.sentence-2)
|
||||
|
||||
[2](#2)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/expressions.tex#L948)
|
||||
|
||||
If the destination type is bool, see [[conv.bool]](conv.bool "7.3.15 Boolean conversions")[.](#2.sentence-1)
|
||||
|
||||
If the
|
||||
source type is bool, the value false is converted to
|
||||
zero and the value true is converted to one[.](#2.sentence-2)
|
||||
|
||||
[3](#3)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/expressions.tex#L954)
|
||||
|
||||
Otherwise, the result is the unique value of the destination type
|
||||
that is congruent to the source integer modulo 2N,
|
||||
where N is the width of the destination type[.](#3.sentence-1)
|
||||
|
||||
[4](#4)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/expressions.tex#L961)
|
||||
|
||||
The conversions allowed as integral promotions are excluded from the set
|
||||
of integral conversions[.](#4.sentence-1)
|
||||
109
cppdraft/conv/lval.md
Normal file
109
cppdraft/conv/lval.md
Normal file
@@ -0,0 +1,109 @@
|
||||
[conv.lval]
|
||||
|
||||
# 7 Expressions [[expr]](./#expr)
|
||||
|
||||
## 7.3 Standard conversions [[conv]](conv#lval)
|
||||
|
||||
### 7.3.2 Lvalue-to-rvalue conversion [conv.lval]
|
||||
|
||||
[1](#1)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/expressions.tex#L612)
|
||||
|
||||
A [glvalue](basic.lval#def:glvalue "7.2.1 Value category [basic.lval]") of a non-function, non-array type T can be converted to
|
||||
a prvalue[.](#1.sentence-1)[43](#footnote-43 "For historical reasons, this conversion is called the âlvalue-to-rvalueâ conversion, even though that name does not accurately reflect the taxonomy of expressions described in [basic.lval].")
|
||||
|
||||
If T is an incomplete type, a
|
||||
program that necessitates this conversion is ill-formed[.](#1.sentence-2)
|
||||
|
||||
If T is a non-class type, the type of the prvalue is
|
||||
the cv-unqualified version of T[.](#1.sentence-3)
|
||||
|
||||
Otherwise, the type of the
|
||||
prvalue is T[.](#1.sentence-4)[44](#footnote-44 "In C++ class and array prvalues can have cv-qualified types. This differs from C, in which non-lvalues never have cv-qualified types.")
|
||||
|
||||
[2](#2)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/expressions.tex#L634)
|
||||
|
||||
When an lvalue-to-rvalue conversion
|
||||
is applied to an expression E, and either
|
||||
|
||||
- [(2.1)](#2.1)
|
||||
|
||||
E is not potentially evaluated, or
|
||||
|
||||
- [(2.2)](#2.2)
|
||||
|
||||
the evaluation of E results in the evaluation of a member Ex of the set of potential results of E, and Ex names a variable x that is not odr-used by Ex ([[basic.def.odr]](basic.def.odr "6.3 One-definition rule")),
|
||||
|
||||
the value contained in the referenced object is not accessed[.](#2.sentence-1)
|
||||
|
||||
[*Example [1](#example-1)*: struct S { int n; };auto f() { S x { 1 };constexpr S y { 2 };return [&](bool b) { return (b ? y : x).n; };}auto g = f();int m = g(false); // undefined behavior: access of x.n outside its lifetimeint n = g(true); // OK, does not access y.n â *end example*]
|
||||
|
||||
[3](#3)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/expressions.tex#L659)
|
||||
|
||||
The result of the conversion is determined according to the
|
||||
following rules:
|
||||
|
||||
- [(3.1)](#3.1)
|
||||
|
||||
If T is cv std::nullptr_t, the result is a
|
||||
null pointer constant ([[conv.ptr]](conv.ptr "7.3.12 Pointer conversions"))[.](#3.1.sentence-1)
|
||||
[*Note [1](#note-1)*:
|
||||
Since the conversion does not access the object to which the glvalue refers,
|
||||
there is no side effect even if T is volatile-qualified ([[intro.execution]](intro.execution "6.10.1 Sequential execution")), and
|
||||
the glvalue can refer to an inactive member of a union ([[class.union]](class.union "11.5 Unions"))[.](#3.1.sentence-2)
|
||||
â *end note*]
|
||||
|
||||
- [(3.2)](#3.2)
|
||||
|
||||
Otherwise, if T has a class
|
||||
type, the conversion copy-initializes the result object from
|
||||
the glvalue[.](#3.2.sentence-1)
|
||||
|
||||
- [(3.3)](#3.3)
|
||||
|
||||
Otherwise, if the object to which the glvalue refers contains an invalid
|
||||
pointer value ([[basic.compound]](basic.compound "6.9.4 Compound types")), the behavior isimplementation-defined[.](#3.3.sentence-1)
|
||||
|
||||
- [(3.4)](#3.4)
|
||||
|
||||
Otherwise, if the bits in the value representation of
|
||||
the object to which the glvalue refers
|
||||
are not valid for the object's type, the behavior is undefined[.](#3.4.sentence-1)
|
||||
[*Example [2](#example-2)*: bool f() {bool b = true; char c = 42;
|
||||
memcpy(&b, &c, 1); return b; // undefined behavior if 42 is not a valid value representation for bool} â *end example*]
|
||||
|
||||
- [(3.5)](#3.5)
|
||||
|
||||
Otherwise, the object indicated by the glvalue is read ([[defns.access]](defns.access "3.1 access"))[.](#3.5.sentence-1)
|
||||
Let V be the value contained in the object[.](#3.5.sentence-2)
|
||||
If T is an integer type,
|
||||
the prvalue result is
|
||||
the value of type T congruent ([[basic.fundamental]](basic.fundamental "6.9.2 Fundamental types")) to V, andV otherwise[.](#3.5.sentence-3)
|
||||
|
||||
[4](#4)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/expressions.tex#L702)
|
||||
|
||||
[*Note [2](#note-2)*:
|
||||
|
||||
See also [[basic.lval]](basic.lval "7.2.1 Value category")[.](#4.sentence-1)
|
||||
|
||||
â *end note*]
|
||||
|
||||
[43)](#footnote-43)[43)](#footnoteref-43)
|
||||
|
||||
For historical reasons, this conversion is called the âlvalue-to-rvalueâ
|
||||
conversion, even though that name does not accurately reflect the taxonomy
|
||||
of expressions described in [[basic.lval]](basic.lval "7.2.1 Value category")[.](#footnote-43.sentence-1)
|
||||
|
||||
[44)](#footnote-44)[44)](#footnoteref-44)
|
||||
|
||||
In C++ class and array prvalues can have cv-qualified types[.](#footnote-44.sentence-1)
|
||||
|
||||
This differs from C, in which non-lvalues never have
|
||||
cv-qualified types[.](#footnote-44.sentence-2)
|
||||
76
cppdraft/conv/mem.md
Normal file
76
cppdraft/conv/mem.md
Normal file
@@ -0,0 +1,76 @@
|
||||
[conv.mem]
|
||||
|
||||
# 7 Expressions [[expr]](./#expr)
|
||||
|
||||
## 7.3 Standard conversions [[conv]](conv#mem)
|
||||
|
||||
### 7.3.13 Pointer-to-member conversions [conv.mem]
|
||||
|
||||
[1](#1)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/expressions.tex#L1075)
|
||||
|
||||
A [null pointer constant](conv.ptr#def:constant,null_pointer "7.3.12 Pointer conversions [conv.ptr]") can be converted to a
|
||||
pointer-to-member
|
||||
type; the result is the [*null member pointer value*](#def:value,null_member_pointer "7.3.13 Pointer-to-member conversions [conv.mem]") of that type and is distinguishable from any pointer to member not
|
||||
created from a null pointer constant[.](#1.sentence-1)
|
||||
|
||||
Such a conversion is called a [*null member pointer conversion*](#def:conversion,null_member_pointer "7.3.13 Pointer-to-member conversions [conv.mem]")[.](#1.sentence-2)
|
||||
|
||||
The conversion of a null pointer
|
||||
constant to a pointer to member of cv-qualified type is a single
|
||||
conversion, and not the sequence of a pointer-to-member conversion
|
||||
followed by a qualification conversion ([[conv.qual]](conv.qual "7.3.6 Qualification conversions"))[.](#1.sentence-3)
|
||||
|
||||
[2](#2)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/expressions.tex#L1090)
|
||||
|
||||
A prvalue of type âpointer to member of B of type cvTâ, where B is a class type, can be converted to
|
||||
a prvalue of type âpointer to member of D of type cvTâ, where D is a complete class derived ([[class.derived]](class.derived "11.7 Derived classes"))
|
||||
from B[.](#2.sentence-1)
|
||||
|
||||
If B is an
|
||||
inaccessible ([[class.access]](class.access "11.8 Member access control")),
|
||||
ambiguous ([[class.member.lookup]](class.member.lookup "6.5.2 Member name lookup")), or virtual ([[class.mi]](class.mi "11.7.2 Multiple base classes")) base
|
||||
class of D, or a base class of a virtual base class ofD, a program that necessitates this conversion is ill-formed[.](#2.sentence-2)
|
||||
|
||||
If class D does not contain the original member and
|
||||
is not a base class of the class containing the original member,
|
||||
the behavior is undefined[.](#2.sentence-3)
|
||||
|
||||
Otherwise,
|
||||
the result of the conversion refers to the same member as the pointer to
|
||||
member before the conversion took place, but it refers to the base class
|
||||
member as if it were a member of the derived class[.](#2.sentence-4)
|
||||
|
||||
The result refers to
|
||||
the member in D's instance of B[.](#2.sentence-5)
|
||||
|
||||
Since the result has
|
||||
type âpointer to member of D of type cv Tâ,
|
||||
indirection through it with a D object is valid[.](#2.sentence-6)
|
||||
|
||||
The result is the same
|
||||
as if indirecting through the pointer to member of B with theB subobject of D[.](#2.sentence-7)
|
||||
|
||||
The null member pointer value is
|
||||
converted to the null member pointer value of the destination
|
||||
type[.](#2.sentence-8)[46](#footnote-46 "The rule for conversion of pointers to members (from pointer to member of base to pointer to member of derived) appears inverted compared to the rule for pointers to objects (from pointer to derived to pointer to base) ([conv.ptr], [class.derived]). This inversion is necessary to ensure type safety. Note that a pointer to member is not an object pointer or a function pointer and the rules for conversions of such pointers do not apply to pointers to members. In particular, a pointer to member cannot be converted to a void*.")
|
||||
|
||||
[46)](#footnote-46)[46)](#footnoteref-46)
|
||||
|
||||
The rule for conversion of pointers to members (from pointer to member
|
||||
of base to pointer to member of derived) appears inverted compared to
|
||||
the rule for pointers to objects (from pointer to derived to pointer to
|
||||
base) ([[conv.ptr]](conv.ptr "7.3.12 Pointer conversions"), [[class.derived]](class.derived "11.7 Derived classes"))[.](#footnote-46.sentence-1)
|
||||
|
||||
This inversion is
|
||||
necessary to ensure type safety[.](#footnote-46.sentence-2)
|
||||
|
||||
Note that a pointer to member is not
|
||||
an object pointer or a function pointer
|
||||
and the rules for conversions
|
||||
of such pointers do not apply to pointers to members[.](#footnote-46.sentence-3)
|
||||
|
||||
In particular, a pointer to member cannot be converted to avoid*[.](#footnote-46.sentence-4)
|
||||
95
cppdraft/conv/prom.md
Normal file
95
cppdraft/conv/prom.md
Normal file
@@ -0,0 +1,95 @@
|
||||
[conv.prom]
|
||||
|
||||
# 7 Expressions [[expr]](./#expr)
|
||||
|
||||
## 7.3 Standard conversions [[conv]](conv#prom)
|
||||
|
||||
### 7.3.7 Integral promotions [conv.prom]
|
||||
|
||||
[1](#1)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/expressions.tex#L853)
|
||||
|
||||
For the purposes of [conv.prom],
|
||||
a [*converted bit-field*](#def:bit-field,converted "7.3.7 Integral promotions [conv.prom]") is a prvalue that is the result of
|
||||
an lvalue-to-rvalue conversion ([[conv.lval]](conv.lval "7.3.2 Lvalue-to-rvalue conversion")) applied to
|
||||
a bit-field ([[class.bit]](class.bit "11.4.10 Bit-fields"))[.](#1.sentence-1)
|
||||
|
||||
[2](#2)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/expressions.tex#L859)
|
||||
|
||||
A prvalue that is not a converted bit-field and has an integer type other thanbool, char8_t, char16_t,char32_t, or wchar_t whose integer conversion
|
||||
rank ([[conv.rank]](conv.rank "6.9.6 Conversion ranks")) is less than the rank of int can be
|
||||
converted to a prvalue of type int if int can represent
|
||||
all the values of the source type; otherwise, the source prvalue can be
|
||||
converted to a prvalue of type unsigned int[.](#2.sentence-1)
|
||||
|
||||
[3](#3)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/expressions.tex#L869)
|
||||
|
||||
A prvalue of an unscoped enumeration type whose underlying type is not
|
||||
fixed can be converted to a prvalue of the first of the following
|
||||
types that can represent all the values of the enumeration ([[dcl.enum]](dcl.enum "9.8.1 Enumeration declarations")): int,unsigned int, long int, unsigned long int,long long int, or unsigned long long int[.](#3.sentence-1)
|
||||
|
||||
If none of the types in that
|
||||
list can represent all the values of the enumeration, a prvalue of an unscoped
|
||||
enumeration type can be converted to a prvalue of the extended integer type with lowest
|
||||
integer conversion rank ([[conv.rank]](conv.rank "6.9.6 Conversion ranks")) greater than the rank of long long in which all the values of the enumeration can be represented[.](#3.sentence-2)
|
||||
|
||||
If there are
|
||||
two such extended types, the signed one is chosen[.](#3.sentence-3)
|
||||
|
||||
[4](#4)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/expressions.tex#L882)
|
||||
|
||||
A prvalue of an unscoped enumeration type whose underlying type is
|
||||
fixed ([[dcl.enum]](dcl.enum "9.8.1 Enumeration declarations")) can be converted to a prvalue of its underlying type[.](#4.sentence-1)
|
||||
|
||||
Moreover,
|
||||
if integral promotion can be applied to its underlying type, a prvalue of an unscoped
|
||||
enumeration type whose underlying type is fixed can also be converted to a prvalue of
|
||||
the promoted underlying type[.](#4.sentence-2)
|
||||
|
||||
[*Note [1](#note-1)*:
|
||||
|
||||
A converted bit-field of enumeration type is treated as
|
||||
any other value of that type for promotion purposes[.](#4.sentence-3)
|
||||
|
||||
â *end note*]
|
||||
|
||||
[5](#5)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/expressions.tex#L893)
|
||||
|
||||
A converted bit-field of integral type can be converted
|
||||
to a prvalue of type int if int can represent all the
|
||||
values of the bit-field; otherwise, it can be converted tounsigned int if unsigned int can represent all the
|
||||
values of the bit-field[.](#5.sentence-1)
|
||||
|
||||
[6](#6)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/expressions.tex#L900)
|
||||
|
||||
A prvalue of typechar8_t, char16_t, char32_t, orwchar_t ([[basic.fundamental]](basic.fundamental "6.9.2 Fundamental types"))
|
||||
(including a converted bit-field that was not
|
||||
already promoted to int or unsigned int according to the rules above)
|
||||
can be converted to a prvalue
|
||||
of the first of the following types that can represent all the values of
|
||||
its underlying type:int,unsigned int,long int,unsigned long int,long long int,unsigned long long int, or
|
||||
its underlying type[.](#6.sentence-1)
|
||||
|
||||
[7](#7)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/expressions.tex#L921)
|
||||
|
||||
A prvalue of type bool can be converted to a prvalue of typeint, with false becoming zero and true becoming
|
||||
one[.](#7.sentence-1)
|
||||
|
||||
[8](#8)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/expressions.tex#L927)
|
||||
|
||||
These conversions are called [*integral promotions*](#def:integral_promotion "7.3.7 Integral promotions [conv.prom]")[.](#8.sentence-1)
|
||||
73
cppdraft/conv/ptr.md
Normal file
73
cppdraft/conv/ptr.md
Normal file
@@ -0,0 +1,73 @@
|
||||
[conv.ptr]
|
||||
|
||||
# 7 Expressions [[expr]](./#expr)
|
||||
|
||||
## 7.3 Standard conversions [[conv]](conv#ptr)
|
||||
|
||||
### 7.3.12 Pointer conversions [conv.ptr]
|
||||
|
||||
[1](#1)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/expressions.tex#L1022)
|
||||
|
||||
A [*null pointer constant*](#def:constant,null_pointer "7.3.12 Pointer conversions [conv.ptr]") is an integer literal ([[lex.icon]](lex.icon "5.13.2 Integer literals")) with
|
||||
value zero
|
||||
or a prvalue of type std::nullptr_t[.](#1.sentence-1)
|
||||
|
||||
A null pointer constant can be
|
||||
converted to a pointer type; the
|
||||
result is the null pointer value of that type ([[basic.compound]](basic.compound "6.9.4 Compound types")) and is
|
||||
distinguishable from every other value of
|
||||
object pointer or function pointer
|
||||
type[.](#1.sentence-2)
|
||||
|
||||
Such a conversion is called a [*null pointer conversion*](#def:conversion,null_pointer "7.3.12 Pointer conversions [conv.ptr]")[.](#1.sentence-3)
|
||||
|
||||
The conversion of a null pointer constant to a pointer to
|
||||
cv-qualified type is a single conversion, and not the sequence of a
|
||||
pointer conversion followed by a qualification
|
||||
conversion ([[conv.qual]](conv.qual "7.3.6 Qualification conversions"))[.](#1.sentence-4)
|
||||
|
||||
A null pointer constant of integral type
|
||||
can be converted to a prvalue of type std::nullptr_t[.](#1.sentence-5)
|
||||
|
||||
[*Note [1](#note-1)*:
|
||||
|
||||
The resulting prvalue is not a null pointer value[.](#1.sentence-6)
|
||||
|
||||
â *end note*]
|
||||
|
||||
[2](#2)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/expressions.tex#L1045)
|
||||
|
||||
A prvalue of type âpointer to cv Tâ, where T is an object type, can be converted to a prvalue of type âpointer tocv voidâ[.](#2.sentence-1)
|
||||
|
||||
The pointer value ([[basic.compound]](basic.compound "6.9.4 Compound types")) is unchanged by this conversion[.](#2.sentence-2)
|
||||
|
||||
[3](#3)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/expressions.tex#L1051)
|
||||
|
||||
A prvalue v of type âpointer to cv Dâ, where D is a complete class type, can be converted to a prvalue of type âpointer tocv Bâ, where B is a base class ([[class.derived]](class.derived "11.7 Derived classes"))
|
||||
of D[.](#3.sentence-1)
|
||||
|
||||
If B is an
|
||||
inaccessible ([[class.access]](class.access "11.8 Member access control")) or
|
||||
ambiguous ([[class.member.lookup]](class.member.lookup "6.5.2 Member name lookup")) base class of D, a program
|
||||
that necessitates this conversion is ill-formed[.](#3.sentence-2)
|
||||
|
||||
If v is a null pointer value,
|
||||
the result is a null pointer value[.](#3.sentence-3)
|
||||
|
||||
Otherwise,
|
||||
if B is a virtual base class of D andv does not point to an object
|
||||
whose type is similar ([[conv.qual]](conv.qual "7.3.6 Qualification conversions")) to D and
|
||||
that is
|
||||
within its lifetime or
|
||||
within its period of construction or destruction ([[class.cdtor]](class.cdtor "11.9.5 Construction and destruction")),
|
||||
the behavior is undefined[.](#3.sentence-4)
|
||||
|
||||
Otherwise,
|
||||
the result is a pointer to the base class subobject of
|
||||
the derived class object[.](#3.sentence-5)
|
||||
111
cppdraft/conv/qual.md
Normal file
111
cppdraft/conv/qual.md
Normal file
@@ -0,0 +1,111 @@
|
||||
[conv.qual]
|
||||
|
||||
# 7 Expressions [[expr]](./#expr)
|
||||
|
||||
## 7.3 Standard conversions [[conv]](conv#qual)
|
||||
|
||||
### 7.3.6 Qualification conversions [conv.qual]
|
||||
|
||||
[1](#1)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/expressions.tex#L755)
|
||||
|
||||
A [*qualification-decomposition*](#def:qualification-decomposition "7.3.6 Qualification conversions [conv.qual]") of a type T is a sequence ofcvi and Pi such that T is âcv0 P0 cv1 P1 ⯠cvnâ1 Pnâ1 cvn Uâ for n ⥠0, where
|
||||
each cvi is a set of cv-qualifiers ([[basic.type.qualifier]](basic.type.qualifier "6.9.5 CV-qualifiers")), and
|
||||
each Pi is
|
||||
âpointer toâ ([[dcl.ptr]](dcl.ptr "9.3.4.2 Pointers")),
|
||||
âpointer to member of class Ci of typeâ ([[dcl.mptr]](dcl.mptr "9.3.4.4 Pointers to members")),
|
||||
âarray of Niâ, or
|
||||
âarray of unknown bound ofâ ([[dcl.array]](dcl.array "9.3.4.5 Arrays"))[.](#1.sentence-1)
|
||||
|
||||
If Pi designates an array,
|
||||
the cv-qualifiers cvi+1 on the element type are also taken as
|
||||
the cv-qualifiers cvi of the array[.](#1.sentence-2)
|
||||
|
||||
[*Example [1](#example-1)*:
|
||||
|
||||
The type denoted by the [*type-id*](dcl.name#nt:type-id "9.3.2 Type names [dcl.name]") const int ** has three qualification-decompositions,
|
||||
taking U as âintâ,
|
||||
as âpointer to const intâ, and
|
||||
as âpointer to pointer to const intâ[.](#1.sentence-3)
|
||||
|
||||
â *end example*]
|
||||
|
||||
[2](#2)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/expressions.tex#L782)
|
||||
|
||||
Two types T1 and T2 are [*similar*](#def:similar_types "7.3.6 Qualification conversions [conv.qual]") if
|
||||
they have qualification-decompositions with the same n such that corresponding Pi components are either the same
|
||||
or one is âarray of Niâ and the other is âarray of unknown bound ofâ,
|
||||
and the types denoted by U are the same[.](#2.sentence-1)
|
||||
|
||||
[3](#3)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/expressions.tex#L790)
|
||||
|
||||
The [*qualification-combined type*](#def:type,qualification-combined "7.3.6 Qualification conversions [conv.qual]") of two types T1 and T2 is the type T3 similar to T1 whose qualification-decomposition is such that:
|
||||
|
||||
- [(3.1)](#3.1)
|
||||
|
||||
for every i>0, cv3i is the union ofcv1i and cv2i,
|
||||
|
||||
- [(3.2)](#3.2)
|
||||
|
||||
if either P1i or P2i is âarray of unknown bound ofâ,P3i is âarray of unknown bound ofâ, otherwise it is P1i, and
|
||||
|
||||
- [(3.3)](#3.3)
|
||||
|
||||
if the resulting cv3i is different from cv1i or cv2i,
|
||||
or the resulting P3i is different from P1i or P2i,
|
||||
then const is added to every cv3k for 0<k<i,
|
||||
|
||||
where cvji and Pji are the components of
|
||||
the qualification-decomposition of Tj[.](#3.sentence-1)
|
||||
|
||||
A prvalue of type T1 can be converted to type T2 if the qualification-combined type of T1 and T2 is T2[.](#3.sentence-2)
|
||||
|
||||
[*Note [1](#note-1)*:
|
||||
|
||||
If a program could assign a pointer of type T** to a pointer of
|
||||
type const T** (that is, if line #1 below were
|
||||
allowed), a program could inadvertently modify a const object
|
||||
(as it is done on line #2)[.](#3.sentence-3)
|
||||
|
||||
For example,int main() {const char c = 'c';char* pc;const char** pcc = &pc; // #1: not allowed*pcc = &c;*pc = 'C'; // #2: modifies a const object}
|
||||
|
||||
â *end note*]
|
||||
|
||||
[*Note [2](#note-2)*:
|
||||
|
||||
Given similar types T1 and T2, this
|
||||
construction ensures that
|
||||
both can be converted to the qualification-combined type of T1 and T2[.](#3.sentence-5)
|
||||
|
||||
â *end note*]
|
||||
|
||||
[4](#4)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/expressions.tex#L832)
|
||||
|
||||
[*Note [3](#note-3)*:
|
||||
|
||||
A prvalue of type âpointer to *cv1* Tâ can be
|
||||
converted to a prvalue of type âpointer to *cv2* Tâ if
|
||||
â*cv2* Tâ is more cv-qualified than â*cv1*Tâ[.](#4.sentence-1)
|
||||
|
||||
A prvalue of type âpointer to member of X of type *cv1*Tâ can be converted to a prvalue of type âpointer to member
|
||||
of X of type *cv2* Tâ if â*cv2*Tâ is more cv-qualified than â*cv1* Tâ[.](#4.sentence-2)
|
||||
|
||||
â *end note*]
|
||||
|
||||
[5](#5)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/expressions.tex#L844)
|
||||
|
||||
[*Note [4](#note-4)*:
|
||||
|
||||
Function types (including those used in pointer-to-member-function types)
|
||||
are never cv-qualified ([[dcl.fct]](dcl.fct "9.3.4.6 Functions"))[.](#5.sentence-1)
|
||||
|
||||
â *end note*]
|
||||
147
cppdraft/conv/rank.md
Normal file
147
cppdraft/conv/rank.md
Normal file
@@ -0,0 +1,147 @@
|
||||
[conv.rank]
|
||||
|
||||
# 6 Basics [[basic]](./#basic)
|
||||
|
||||
## 6.9 Types [[basic.types]](basic.types#conv.rank)
|
||||
|
||||
### 6.9.6 Conversion ranks [conv.rank]
|
||||
|
||||
[1](#1)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/basic.tex#L6107)
|
||||
|
||||
Every integer type has an [*integer conversion rank*](#def:integer_conversion_rank) defined as follows:
|
||||
|
||||
- [(1.1)](#1.1)
|
||||
|
||||
No two signed integer types other than char and signedchar (if char is signed) have the same rank, even if they have
|
||||
the same representation[.](#1.1.sentence-1)
|
||||
|
||||
- [(1.2)](#1.2)
|
||||
|
||||
The rank of a signed integer type is greater than the rank
|
||||
of any signed integer type with a smaller width[.](#1.2.sentence-1)
|
||||
|
||||
- [(1.3)](#1.3)
|
||||
|
||||
The rank of long long int is greater
|
||||
than the rank of long int, which is greater than
|
||||
the rank of int, which is greater than the rank ofshort int, which is greater than the rank ofsigned char[.](#1.3.sentence-1)
|
||||
|
||||
- [(1.4)](#1.4)
|
||||
|
||||
The rank of any unsigned integer type equals the rank of the
|
||||
corresponding signed integer type[.](#1.4.sentence-1)
|
||||
|
||||
- [(1.5)](#1.5)
|
||||
|
||||
The rank of any standard integer type is greater than the
|
||||
rank of any extended integer type with the same width[.](#1.5.sentence-1)
|
||||
|
||||
- [(1.6)](#1.6)
|
||||
|
||||
The rank of char equals the rank of signed char and unsigned char[.](#1.6.sentence-1)
|
||||
|
||||
- [(1.7)](#1.7)
|
||||
|
||||
The rank of bool is less than the rank of all
|
||||
standard integer types[.](#1.7.sentence-1)
|
||||
|
||||
- [(1.8)](#1.8)
|
||||
|
||||
The ranks of char8_t, char16_t, char32_t, andwchar_t equal the ranks of their underlying
|
||||
types ([[basic.fundamental]](basic.fundamental "6.9.2 Fundamental types"))[.](#1.8.sentence-1)
|
||||
|
||||
- [(1.9)](#1.9)
|
||||
|
||||
The rank of any extended signed integer type relative to another
|
||||
extended signed integer type with the same width is implementation-defined, but still subject to the other rules for determining the integer
|
||||
conversion rank[.](#1.9.sentence-1)
|
||||
|
||||
- [(1.10)](#1.10)
|
||||
|
||||
For all integer types T1, T2, and T3, ifT1 has greater rank than T2 and T2 has greater
|
||||
rank than T3, then T1 has greater rank thanT3[.](#1.10.sentence-1)
|
||||
|
||||
[*Note [1](#note-1)*:
|
||||
|
||||
The integer conversion rank is used in the definition of the integral
|
||||
promotions ([[conv.prom]](conv.prom "7.3.7 Integral promotions")) and the usual arithmetic
|
||||
conversions ([[expr.arith.conv]](expr.arith.conv "7.4 Usual arithmetic conversions"))[.](#1.sentence-2)
|
||||
|
||||
â *end note*]
|
||||
|
||||
[2](#2)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/basic.tex#L6160)
|
||||
|
||||
Every floating-point type has a [*floating-point conversion rank*](#def:conversion_rank,floating-point "6.9.6 Conversion ranks [conv.rank]") defined as follows:
|
||||
|
||||
- [(2.1)](#2.1)
|
||||
|
||||
The rank of a floating point type T is greater than
|
||||
the rank of any floating-point type
|
||||
whose set of values is a proper subset of the set of values of T[.](#2.1.sentence-1)
|
||||
|
||||
- [(2.2)](#2.2)
|
||||
|
||||
The rank of long double is greater than
|
||||
the rank of double,
|
||||
which is greater than the rank of float[.](#2.2.sentence-1)
|
||||
|
||||
- [(2.3)](#2.3)
|
||||
|
||||
Two extended floating-point types with the same set of values have equal ranks[.](#2.3.sentence-1)
|
||||
|
||||
- [(2.4)](#2.4)
|
||||
|
||||
An extended floating-point type with the same set of values as
|
||||
exactly one cv-unqualified standard floating-point type
|
||||
has a rank equal to the rank of that standard floating-point type[.](#2.4.sentence-1)
|
||||
|
||||
- [(2.5)](#2.5)
|
||||
|
||||
An extended floating-point type with the same set of values as
|
||||
more than one cv-unqualified standard floating-point type
|
||||
has a rank equal to the rank of double[.](#2.5.sentence-1)
|
||||
[*Note [2](#note-2)*:
|
||||
The treatment of std::float64_t differs from
|
||||
that of the analogous _Float64 in C,
|
||||
for example on platforms where all oflong double,double, andstd::float64_t have the same set of values (see ISO/IEC 9899:2024 H.4.2)[.](#2.5.sentence-2)
|
||||
â *end note*]
|
||||
|
||||
[*Note [3](#note-3)*:
|
||||
|
||||
The conversion ranks of floating-point types T1 and T2 are unordered if the set of values of T1 is
|
||||
neither a subset nor a superset of the set of values of T2[.](#2.sentence-2)
|
||||
|
||||
This can happen when one type has both a larger range and a lower precision
|
||||
than the other[.](#2.sentence-3)
|
||||
|
||||
â *end note*]
|
||||
|
||||
[3](#3)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/basic.tex#L6200)
|
||||
|
||||
Floating-point types that have equal floating-point conversion ranks
|
||||
are ordered by floating-point conversion subrank[.](#3.sentence-1)
|
||||
|
||||
The subrank forms a total order among types with equal ranks[.](#3.sentence-2)
|
||||
|
||||
The typesstd::float16_t,std::float32_t,std::float64_t, andstd::float128_t ([[stdfloat.syn]](stdfloat.syn "17.4.2 Header <stdfloat> synopsis"))
|
||||
have a greater conversion subrank than any standard floating-point type
|
||||
with equal conversion rank[.](#3.sentence-3)
|
||||
|
||||
Otherwise, the conversion subrank order isimplementation-defined[.](#3.sentence-4)
|
||||
|
||||
[4](#4)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/basic.tex#L6214)
|
||||
|
||||
[*Note [4](#note-4)*:
|
||||
|
||||
The floating-point conversion rank and subrank are used in
|
||||
the definition of the usual arithmetic conversions ([[expr.arith.conv]](expr.arith.conv "7.4 Usual arithmetic conversions"))[.](#4.sentence-1)
|
||||
|
||||
â *end note*]
|
||||
29
cppdraft/conv/rval.md
Normal file
29
cppdraft/conv/rval.md
Normal file
@@ -0,0 +1,29 @@
|
||||
[conv.rval]
|
||||
|
||||
# 7 Expressions [[expr]](./#expr)
|
||||
|
||||
## 7.3 Standard conversions [[conv]](conv#rval)
|
||||
|
||||
### 7.3.5 Temporary materialization conversion [conv.rval]
|
||||
|
||||
[1](#1)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/expressions.tex#L734)
|
||||
|
||||
A prvalue of type T can be converted to an xvalue of type T[.](#1.sentence-1)
|
||||
|
||||
This conversion initializes a temporary object ([[class.temporary]](class.temporary "6.8.7 Temporary objects")) of type T from the prvalue
|
||||
by evaluating the prvalue with the temporary object as its result object,
|
||||
and produces an xvalue denoting the temporary object[.](#1.sentence-2)
|
||||
|
||||
T shall be a complete type[.](#1.sentence-3)
|
||||
|
||||
[*Note [1](#note-1)*:
|
||||
|
||||
If T is a class type (or array thereof),
|
||||
it must have an accessible and non-deleted destructor;
|
||||
see [[class.dtor]](class.dtor "11.4.7 Destructors")[.](#1.sentence-4)
|
||||
|
||||
â *end note*]
|
||||
|
||||
[*Example [1](#example-1)*: struct X { int n; };int k = X().n; // OK, X() prvalue is converted to xvalue â *end example*]
|
||||
Reference in New Issue
Block a user