4.3 KiB
[conv.qual]
7 Expressions [expr]
7.3 Standard conversions [conv]
7.3.6 Qualification conversions [conv.qual]
A qualification-decomposition 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]), and each Pi is âpointer toâ ([dcl.ptr]), âpointer to member of class Ci of typeâ ([dcl.mptr]), âarray of Niâ, or âarray of unknown bound ofâ ([dcl.array]).
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.
[Example 1:
The type denoted by the type-id const int ** has three qualification-decompositions, taking U as âintâ, as âpointer to const intâ, and as âpointer to pointer to const intâ.
â end example]
Two types T1 and T2 are similar 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.
The qualification-combined type of two types T1 and T2 is the type T3 similar to T1 whose qualification-decomposition is such that:
for every i>0, cv3i is the union ofcv1i and cv2i,
if either P1i or P2i is âarray of unknown bound ofâ,P3i is âarray of unknown bound ofâ, otherwise it is P1i, and
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.
A prvalue of type T1 can be converted to type T2 if the qualification-combined type of T1 and T2 is T2.
[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).
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:
Given similar types T1 and T2, this construction ensures that both can be converted to the qualification-combined type of T1 and T2.
â end note]
[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 âcv1Tâ.
A prvalue of type âpointer to member of X of type cv1Tâ can be converted to a prvalue of type âpointer to member of X of type cv2 Tâ if âcv2Tâ is more cv-qualified than âcv1 Tâ.
â end note]
[Note 4:
Function types (including those used in pointer-to-member-function types) are never cv-qualified ([dcl.fct]).
â end note]