74 lines
3.0 KiB
Markdown
74 lines
3.0 KiB
Markdown
[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)
|