Movatterモバイル変換


[0]ホーム

URL:


7 Expressions[expr]

7.3 Standard conversions[conv]

7.3.6 Qualification conversions[conv.qual]

Aqualification-decomposition of a typeTis a sequence of andsuch thatT isU” forn  ≥ 0,whereeach is a set of cv-qualifiers ([basic.type.qualifier]), andeach 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 asthe cv-qualifiers of the array.
[Example 1: 
The type denoted by thetype-idconstint**has three qualification-decompositions,takingUas “int”,as “pointer toconstint”, andas “pointer to pointer toconstint.
— end example]
Two typesT1 andT2 aresimilar ifthey have qualification-decompositions with the samensuch that corresponding components are either the sameor one is “array of” and the other is “array of unknown bound of”,and the types denoted byU are the same.
Thequalification-combined type of two typesT1 andT2is the typeT3similar toT1 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,thenconst is added to every for,
where and are the components ofthe qualification-decomposition ofTj.
A prvalue of typeT1can be converted to typeT2if the qualification-combined type ofT1 andT2 isT2.
[Note 1: 
If a program could assign a pointer of typeT** to a pointer oftypeconstT** (that is, if line #1 below wereallowed), a program could inadvertently modify a const object(as it is done on line #2).
For example,int main(){constchar c='c';char* pc;constchar** pcc=&pc;// #1: not allowed*pcc=&c;*pc='C';// #2: modifies a const object}
— end note]
[Note 2: 
Given similar typesT1 andT2, thisconstruction ensures thatboth can be converted to the qualification-combined type ofT1 andT2.
— end note]
[Note 3: 
A prvalue of type “pointer tocv1T” can beconverted to a prvalue of type “pointer tocv2T” if“cv2T” is more cv-qualified than “cv1T.
A prvalue of type “pointer to member ofX of typecv1T” can be converted to a prvalue of type “pointer to memberofX of typecv2T” if “cv2T” is more cv-qualified than “cv1T.
— end note]
[Note 4: 
Function types (including those used in pointer-to-member-function types)are never cv-qualified ([dcl.fct]).
— end note]

[8]ページ先頭

©2009-2026 Movatter.jp