From 34a9f5d11ae09a8fca37dfc224f65dea1ffc4fc1 Mon Sep 17 00:00:00 2001 From: Abhinav Agarwal Date: Wed, 17 Jun 2026 08:49:55 -0700 Subject: [PATCH] [expr.prim.splice] Const-ify variable-template splice in contract predicate P3598R0 added contract-predicate const-ification to [expr.prim.splice] paragraph 2 for splice-specifier expressions designating variables, but not to paragraph 4's template splice-specialization-specifier form. A variable-template specialization accessed via template [:^^var:]<...> was therefore mutable in a contract predicate, while the same object is const via [:^^var<...>:] or the id-expression var<...>. Name the expression E and apply the same const-ification (using U to avoid clashing with the template T) so all forms agree. --- source/expressions.tex | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/source/expressions.tex b/source/expressions.tex index 72f77d87bb..9fda8fd06f 100644 --- a/source/expressions.tex +++ b/source/expressions.tex @@ -3659,7 +3659,7 @@ \end{note} \pnum -For a \grammarterm{splice-expression} of +For a \grammarterm{splice-expression} $E$ of the form \tcode{template \grammarterm{splice-specialization-specifier}}, the \grammarterm{splice-specifier} of the \grammarterm{splice-specialization-specifier} @@ -3676,8 +3676,20 @@ Otherwise, if $T$ is a variable template, let $S$ be the specialization of $T$ corresponding to the template argument list of the \grammarterm{splice-specialization-specifier}. -The expression is an lvalue referring to -the object associated with $S$ and has the same type as that of $S$. +$E$ is an lvalue referring to +the object or function associated with or referenced by $S$. +If $E$ appears in the predicate of a contract assertion $C$\iref{basic.contract} +and $S$ is +\begin{itemize} +\item +a variable declared outside of $C$ +of object type \tcode{U}, or +\item +a variable declared outside of $C$ +of type ``reference to \tcode{U}'', +\end{itemize} +then the type of $E$ is \tcode{const U}, +otherwise $E$ has the same type as that of $S$. \item Otherwise, the expression is ill-formed. \end{itemize}