Name n3844, alx-0086r1 - comparable types Principles - Keep the language small and simple Category Editorial Author Christopher Bazley Alejandro Colomar Cc: Philipp Klaus Krause Cc: Aaron Ballman History r0 (2026-02-06): - Initial draft. Fork from n3674. r1 (2026-02-10; n3844): - Document the term access qualifiers. - Add n3795 to See also. Description Too often, we use the phrase "qualified or unqualified type". It implicitly does not include the _Atomic qualifier. Let's use a specific term for that: "comparable type". This is a spin-off of n3674. See also Proposed wording Based on N3783. 6.2.5 Types @@ p31+1 +The +const, +restrict, +and +volatile +qualifiers +are collectively called +the standard access qualifiers. +There may also be implementation-defined access qualifiers. +The standard access qualifiers +and any implementation-defined access qualifiers +are collectively called +access qualifiers. @@ p32 Any type so far mentioned is an unqualified type. Each unqualified type has several qualified versions of its type,40) corresponding to the combinations of -one, two, or all three of -the const, volatile, and restrict qualifiers. +some or all access qualifiers. The qualified or unqualified versions of a type are distinct types that belong to -the same type category +the same type category. -and have the same representation and alignment requirements.41) An array and its element type are always considered to be identically qualified.42) Any other derived type is not qualified by the qualifiers (if any) of the type from which it is derived. ## The above will be now covered by comparable type rules. ## Types in the same type category are comparable types. @@ Footnote 41 -41) -The same representation and alignment requirements -are meant to imply interchangeability as -arguments to functions, -return values from functions, -and members of unions. 6.2.6.3 Pointer types and nullptr_t @@ p1 A pointer to void shall have the same representation and alignment requirements as a pointer to a character type.41) Similarly, pointers to -qualified or unqualified versions of compatible types +comparable types shall have the same representation and alignment requirements. All pointers to structure types shall have the same representation and alignment requirements as each other. All pointers to union types shall have the same representation and alignment requirements as each other. Pointers to other types may not have the same representation or alignment requirements. ## This guarantees that char** and const char*const* have the ## same representation and alignment. 6.2 Concepts ## Add new subsections after 6.2.7 ("Compatible type and composite type") +6.2.7+1 Comparable type +1 + Two types are comparable types + if they would be compatible types + if all access qualifiers + were removed from both types. +2 + Comparable complete object types + shall have the same + representation and alignment requirements. + XXX) + +XXX) + The same representation and alignment requirements + are meant to imply interchangeability as + arguments to functions, + return values from functions, + and members of unions. 6.5.7 Additive operators @@ Constraints, p3 For subtraction, one of the following shall hold: -- [...] -- both operands are pointers to - qualified or unqualified versions of compatible + comparable complete object types; or -- [...] 6.5.9 Relational operators @@ Constraints, p2 One of the following shall hold: -- [...] -- both operands are pointers to - qualified or unqualified versions of compatible + comparable object types. 6.5.10 Equality operators @@ Constraints, p2 One of the following shall hold: -- [...] -- both operands are pointers to - qualified or unqualified versions of compatible + comparable types. -- one operand is a pointer to an object type and the other is a pointer to a qualified or unqualified version of void; -- [...] -- [...] -- [...] 6.5.16 Conditional operator @@ Constraints, p3 One of the following shall hold for the second and third operands:110) -- [...] -- [...] -- [...] -- both operands are pointers to - qualified or unqualified versions of compatible + comparable types; -- [...] -- [...] -- [...] 6.5.17.2 Expressions :: Assignment operators :: Simple assignment @@ Constraints, p1 One of the following shall hold:113) -- [...] -- [...] -- the left operand has atomic, qualified, or unqualified pointer type, and (considering the type the left operand would have after lvalue conversion) both operands are pointers to - qualified or unqualified versions of compatible + comparable types, and the type pointed to by the left operand has all the qualifiers of the type pointed to by the right operand; -- [...] -- [...] -- [...] -- [...] @@ Semantics, p3 If the value being stored in an object is read from another object that overlaps in any way the storage of the first object, then the two objects shall occupy exactly the same storage and shall have -qualified or unqualified versions of a compatible +comparable type; otherwise, the behavior is undefined. 7.16.2.2 The va_arg macro @@ Description, p2 ... except for the following cases: -- both ypes are pointers to - qualified or unqualified versions of compatible + comparable types; -- [...] -- [...] -- [...]