Files
cppdraft_translate/cppdraft/conv/ptr.md
2025-10-25 03:02:53 +03:00

3.0 KiB
Raw Blame History

[conv.ptr]

7 Expressions [expr]

7.3 Standard conversions [conv]

7.3.12 Pointer conversions [conv.ptr]

1

#

A null pointer constant is an integer literal ([lex.icon]) with value zero or a prvalue of type std::nullptr_t.

A null pointer constant can be converted to a pointer type; the result is the null pointer value of that type ([basic.compound]) and is distinguishable from every other value of object pointer or function pointer type.

Such a conversion is called a null pointer conversion.

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]).

A null pointer constant of integral type can be converted to a prvalue of type std::nullptr_t.

[Note 1:

The resulting prvalue is not a null pointer value.

— end note]

2

#

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”.

The pointer value ([basic.compound]) is unchanged by this conversion.

3

#

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]) of D.

If B is an inaccessible ([class.access]) or ambiguous ([class.member.lookup]) base class of D, a program that necessitates this conversion is ill-formed.

If v is a null pointer value, the result is a null pointer value.

Otherwise, if B is a virtual base class of D andv does not point to an object whose type is similar ([conv.qual]) to D and that is within its lifetime or within its period of construction or destruction ([class.cdtor]), the behavior is undefined.

Otherwise, the result is a pointer to the base class subobject of the derived class object.