[conv.qual] (original) (raw)
7 Expressions [expr]
7.3 Standard conversions [conv]
7.3.6 Qualification conversions [conv.qual]
A qualification-decomposition of a type Tis a sequence of and such that T is“ ⋯ U” for n ≥ 0,where each is a set of cv-qualifiers ([basic.type.qualifier]), and each is “pointer to” ([dcl.ptr]), “pointer to member of class of type” ([dcl.mptr]), “array of ”, or “array of unknown bound of” ([dcl.array]).
If designates an array, the cv-qualifiers on the element type are also taken as the cv-qualifiers of the array.
[Example 1:
The type denoted by the type-id const int **has three qualification-decompositions, taking Uas “int”, as “pointer to const int”, and as “pointer to pointer to const int”.
— _end example_]
The n-tuple of cv-qualifiers after the first one in the longest qualification-decomposition of T, that is,, is called thecv-qualification signature of T.
Two types T1 and T2 are similar if they have qualification-decompositions with the same nsuch that corresponding components are either the same or one is “array of ” 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 T2is the type T3similar to T1 whose qualification-decomposition is such that:
- for every , is the union of and ,
- if either or is “array of unknown bound of”, is “array of unknown bound of”, otherwise it is , and
- if the resulting is different from or , or the resulting is different from or , then const is added to every for ,
where and are the components of the qualification-decomposition of Tj.
A prvalue of type T1can be converted to type T2if 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; *pcc = &c;*pc = 'C'; }
— _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 “cv1 T”.
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”.
— _end note_]
[Note 4:
Function types (including those used in pointer-to-member-function types) are never cv-qualified ([dcl.fct]).
— _end note_]