Search code examples
c++constantsimplicit-conversionqualifiers

const qualification conversion


From (4.4/1 ) It reads

An rvalue of type “pointer to cv1 T” can be converted to an rvalue of type “pointer to cv2 T” if “cv2 T” is more cv-qualified than “cv1 T.”

I don't know where the standard defines 'more cv-qualifield' type but as I understood a declarator with const is more cv-qualified than than a non-const.

For following conversions, how does the quote from standard fits in or how you know which one is less or more cv-qualifed?

int *const c1 = 0;
int const* c2 = 0;
const int *const c3 = 0;

c1 = c2; // allowed
c1 = c3; // allowed

Update:

c2 = c1;
c2 = c3;

Solution

  • Table 6 in 3.9.3/4 gives the partial ordering of cv-qualifiers and 3.9.3/4 also gives the definition of more cv-qualified.

    • no cv-qualifier < const
    • no cv-qualifier < volatile
    • no cv-qualifier < const volatile
    • const < const volatile
    • volatile < const volatile

    C++23 draft N4928 has this table in §6.8.5 (5), [basic.type.qualifier]. Find it on eel.is.