[expr.prim.splice] Should variable-template splice specializations be constified in contract predicates?

Open
#9,172 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
38/100
Issue type
Documentation
Clarity
Mostly clear
Activity status
Quiet
Tech stack
cpp
Domain
documentation

Research direction

Start with the expr.prim.splice subclause and compare the variable-template splice-specialization-specifier with the plain splice-specifier. Read P3598R0, P2996R13, and CWG3158, then determine whether both forms need the same contract-predicate constification and whether the reference-variable wording also needs alignment.

Written by the indexing model from the issue text.

Description

Subclause: [expr.prim.splice]

P3598R0, resolving CWG3158, added contract-predicate constification for the plain splice-specifier form. However, the variable-template splice-specialization-specifier form from P2996R13 still says unconditionally that the expression has the same type as the selected specialization.

For example:

template<int I> int var = I;

void f()
  pre(template [:^^var:]<0> == 0) // not constified: template splice-specialization-specifier
  pre([:^^var<0>:] == 0);         // constified: plain splice-specifier
Expression What is inside [: ... :]
template [:^^var:]<0> Template var; <0> is outside the splice
[:^^var<0>:] Specialization var<0>; <0> is inside the splice

Both expressions refer to var<0>. Is this difference intentional?


The difference affects well-formedness: only the specialization form can be used to modify the variable within the predicate.

void g()
  pre((template [:^^var:]<0> = 1)) // well-formed: non-const lvalue, assignable
  pre(([:^^var<0>:] = 1));        // ill-formed: const lvalue

If not, should the variable-template branch in [expr.prim.splice] apply the same shallow constification rule when the expression appears in a contract predicate?

Separately, that branch still says only “the object associated with S”. A reference variable-template specialization can instead refer to a function. That wording alignment seems independent of the constification question.

Dominant language
TeX
Stars
221
Forks
813
Avg merge
17h 45m
Merged PRs (30d)
34

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from cplusplus/draft

All issues in cplusplus/draft

Similar issues

More Documentation issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.