You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
CWG3158 [expr.prim.id.qual] Constification fails to apply to splice-expressions #844
Issue description:
The P2900 "constification" mechanism specifically applies to unqualified-ids. The mechanism can therefore be bypassed by instead referring to the same entity by way of a splice-expression, even though that "bypass" can be trivially detected during translation. It seems clear that the same constification-transform should apply to any such splice-expression referring to any such "non-local" variable or object within a contract assertion.
voidf(int p)
pre([&] { ++p; returntrue; }()) // error: unqualified-id 'p' has const type
pre([&] { ++[:^^p:]; returntrue; }()) // lol sounds great
{
}
Suggested resolution:
Break [expr.prim.splice]/2.3 into two paragraphs and modify as follows:
Otherwise, if S is an object of type T, the expression
is an lvalue designating S,
is a bit-field if and only if S is a bit-field, and
has the type constT if the expression appears in a contract assertion C such that S is introduced by a variable declared outside of C or otherwise T.
Otherwise, if S is an object or a non-static data member, the expression is an lvalue designating S. The expression has the same type as that of S, and is a bit-field if and only if S is a bit-field.
Modify [expr.prim.splice]/2.5 as follows:
Otherwise, if S is a variable or a structured binding, where T is the type of S, S shall either have static or thread storage duration or shall inhabit a scope enclosing the expression. The expression:
is an lvalue referring to the object or function X associated with or referenced by S,
has the same type as that of S, and is a bit-field if and only if X is a bit-field, and
has the type constT if the expression appears in a contract assertion C such that S is declared outside of C or otherwise T.
A few other wording approaches might be worth considering:
We could define the "constification" transform in a more reusable way in e.g., [basic.contract] (e.g., as a mapping from a (designating-expression, entity)-pair to a constified type), then use that definition in both [expr.prim.id.unqual] and [expr.prim.splice].
We could try to perform the adjustment holistically in [expr.type] for all glvalues whose result is an entity declared outside of a contract assertion.
changed the title [-][section.label] Constification fails to apply to splice-expressions[/-][+] [expr.prim.id.qual] Constification fails to apply to splice-expressions[/+]on Feb 6, 2026
There is also the conceptual option to apply the constification on the reflect-expression, or to both the reflect-expression and the splice-expression. Any thoughts on that?
Also, constification has a been a hot topic in EWG, so I'll forward this to EWG for consideration.
changed the title [-] [expr.prim.id.qual] Constification fails to apply to splice-expressions[/-][+]CWG3158 [expr.prim.id.qual] Constification fails to apply to splice-expressions[/+]on Feb 22, 2026
Activity
[-][section.label] Constification fails to apply to splice-expressions[/-][+] [expr.prim.id.qual] Constification fails to apply to splice-expressions[/+]jensmaurer commentedon Feb 22, 2026
There is also the conceptual option to apply the constification on the reflect-expression, or to both the reflect-expression and the splice-expression. Any thoughts on that?
Also, constification has a been a hot topic in EWG, so I'll forward this to EWG for consideration.
jensmaurer commentedon Feb 22, 2026
CWG3158
[-] [expr.prim.id.qual] Constification fails to apply to splice-expressions[/-][+]CWG3158 [expr.prim.id.qual] Constification fails to apply to splice-expressions[/+]