Name
n3907, alx-0091r1 - substitutable types
Principles
- Keep the language small and simple
Category
Editorial
Author
Christopher Bazley <chris.bazley.wg14@gmail.com>
Alejandro Colomar <alx@kernel.org>
History
<https://www.alejandro-colomar.es/src/alx/alx/std/wg14/alx-0091.git/>
r0 (2026-04-16):
- Initial draft. Fork from n3674.
r1 (2026-04-17; n3907):
- ffix
- Add changes to 6.5.1.
Description
This proposal adds the concept of 'substitutable type', but
doesn't change anything normatively. At this time, it's only
used to simplify one bullet in 6.5.17.2 ("Simple assignment").
Future proposals will expand this substitutable type to allow
more substitutions. The current proposal only sets up the
infrastructure, so that those future proposals are smaller and
simpler.
Relationship with other proposals
This is a preparation for (spin off from) n3749 (which is itself
a spin-off from n3674). n3749 was voted along the lines in Brno:
Opinion Poll: Would WG14 like to adopt something along
the lines of N3629 into C2y? 3-0-1 + 18-0-5 = 23-0-6
Admittedly, I've changed the wording significantly from n3749,
so none of the text in alx-0086 comes from n3749. Rather, I
derived the text from Chris's type variance paper: n3674. That
paper was voted along the lines in 202602:
Opinion Poll: Would WG14 like to adopt something along
the lines of N3674 into C2y? 19-0-8 strong direction
I took the wording about substitutable types almost exactly from
that paper, with very small changes. So we have indeed reviewed
this wording in a meeting; almost the exact wording, indeed.
See also
<https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3749.pdf>
<https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3674.pdf>
Proposed wording
Based on N3854 + n3875 (2026-04-12; Colomar; "comparable types").
6.2 Concepts
## Add new subsection after 6.2.7+1 ("Comparable type")
+6.2.7+2 Substitutable type
+1
+ In certain circumstances,
+ an expression of pointer type
+ can be assigned to an lvalue of a different pointer type.
+ In such cases,
+ the referenced type of the assigned expression
+ is said to be
+ <i>substitutable for</i>
+ the referenced type of the lvalue
+ to which it is assigned.
+2
+ A type, <tt>Q</tt>,
+ is substitutable for another type, <tt>R</tt>,
+ if the following conditions are satisfied:
+ --
+ <tt>Q</tt> and <tt>R</tt>
+ are comparable types;
+ and
+ --
+ <tt>R</tt> has all the qualifiers of <tt>Q</tt>.
6.5.1 Expressions :: General
@@ Semantics, p9
An object shall have its stored value accessed
only by an lvalue expression that has
one of the following types:
71)
--
a type
- compatible with
+ for which
the effective type of the object
+ is substitutable
,
- --
- a qualified version of
- a type compatible with
- the effective type of the object,
--
the signed or unsigned type corresponding to
a type
- compatible with
+ for which
the underlying type of
the effective type of the object
+ is substitutable
,
- --
- the signed or unsigned type corresponding to
- a type compatible with
- a qualified version of
- the underlying type of
- the effective type of the object,
-- [...]
-- [...]
6.5.17.2 Expressions :: Assignment operators :: Simple assignment
@@ Constraints, p1
One of the following shall hold:96)
-- [...]
-- [...]
--
- 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 comparable types,
+ both operands have pointer types,
and the type pointed to by the
- left
+ right
operand
- has all the qualifiers of
+ is substitutable for
the type pointed to by the
- right
+ left
operand;
-- [...]
-- [...]
-- [...]
-- [...]