Name n3574 - Adopt qualifier conversion rules from C++ Principles - Codify existing practice to address evident deficiencies. - Do not leave features in an underdeveoped state. - Enable secure programming. - Facilitate interoperability. Category Language; conversions; pointers. Author Alejandro Colomar Cc: Jonathan Wakely Cc: Joseph Myers Cc: наб History r0 (2025-03-15): - Initial draft. r1 (2025-03-17): - Fix recursive wording. The types in tN might be qualified at any level as long as the corresponding uN is qualified, regardless of the qualification of t(N-1). At least that's what g++(1) seems to accept. r2 (2025-05-04): - Fix typos. - Remove bogus link from 'See also'. - Add links to 'See also'. - Mention n3510 in 'See also'. - Use the wording in C++11. The wording I had was bogus; and the wording in the current versions of C++ is too complex for me to understand it. The wording of C++11 is slightly less powerful than the current one, but on the other hand it's not a bad idea to fall short on allowed conversions, just in case. If we want to lift more restrictions, we're always in time. r3 (2025-06-01): - tfix. Description C is too strict regarding qualifiers, and requires the programmer to do casts or have functions with unnecessarily unqualified APIs. C++ has shown that certain assignments can be done safely. The following is forbidden by C, but allowed by C++: char *p; const char *const *pp = &p; See also This proposal would interact with n3510 (see link above). Both proposals intend to reduce the use of casts for converting pointers, in order to have stronger type safety. n3510 focuses on function pointers, while this proposal focuses on pointers to pointers. Both proposals are compatible (and beneficial to each other), although care should be taken to make sure there are no merge conflicts. This proposal should be simpler than n3510, since we have prior art in C++, where it has been tested for a long time. Proposed wording Based on N3550. 6.3.3.3 Conversions :: Other operands :: Pointers @@ New p after p2 +A conversion can add qualifiers +at levels other than the first multi-level pointers, +subject to the following rules: + Two pointer types T1 and T2 + are similar + if there exists a type T + and integer n > 0 + such that: + + T1 is q_1,0 pointer to + q_q1,1 pointer to ... + q_1,n-1 pointer to q_1,n T + and + T2 is q_2,0 pointer to + q_q2,1 pointer to ... + q_2,n-1 pointer to q_2,n T + +where each q_i,j is a set of qualifiers. +The n-tuple of qualifiers +after the first in a pointer type +--e.g., q_1,1, q_1,2, ... q_1,n + in the pointer type T1-- +is called +the qualification signature of the pointer type. +An expression of type T1 +can be converted to type T2 +if and only if the following conditions are satisfied: + - the pointer types are similar. + - for every j > 0, + if a qualifier is in q_1,j + the same qualifier is in q_2,j. + - if q_1,j and q_2,j are different, + then const is in every q_2,k + for 0 < k < j.