Files
2025-10-25 03:02:53 +03:00

112 lines
4.3 KiB
Markdown
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

[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.6Qualification 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.5CV-qualifiers")), and
each Pi is
“pointer to” ([[dcl.ptr]](dcl.ptr "9.3.4.2Pointers")),
“pointer to member of class Ci of type” ([[dcl.mptr]](dcl.mptr "9.3.4.4Pointers to members")),
“array of Ni”, or
“array of unknown bound of” ([[dcl.array]](dcl.array "9.3.4.5Arrays"))[.](#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.2Type 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.6Qualification 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.6Qualification 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* € can be
converted to a prvalue of type “pointer to *cv2* € if
“*cv2* € is more cv-qualified than “*cv1*€[.](#4.sentence-1)
A prvalue of type “pointer to member of X of type *cv1*€ can be converted to a prvalue of type “pointer to member
of X of type *cv2* € if “*cv2*€ is more cv-qualified than “*cv1* €[.](#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.6Functions"))[.](#5.sentence-1)
— *end note*]