This is an unofficial snapshot of the ISO/IEC JTC1 SC22 WG21 Core Issues List revision 115d. See http://www.open-std.org/jtc1/sc22/wg21/ for the official list.

2024-10-26


2777. Type of id-expression denoting a template parameter object

Section: 13.2  [temp.param]     Status: DRWP     Submitter: Jim X     Date: 2023-07-26

[Accepted as a DR at the March, 2024 meeting.]

The type of a template parameter object is specified to be const T in 13.2 [temp.param] paragraph 8:

An id-expression naming a non-type template-parameter of class type T denotes a static storage duration object of type const T, known as a template parameter object, whose value is that of the corresponding template argument after it has been converted to the type of the template-parameter. ...

However, it is unclear what the type of an id-expression is that refers to such an object. There is implementation divergence in the treatment of the following example:

  struct A {};

  template<auto a, auto x>  // also consider A a and const auto x
  int f() {
    decltype(a) b;          // also consider decltype((a))
    A& rb = b;
    decltype(x) y;
    int& ry = y;
  }

  int x = f<A{}, 42>();

Note that non-type template parameters are handled specially for decltype, as specified in 9.2.9.6 [dcl.type.decltype] paragraph 1:

For an expression E, the type denoted by decltype(E) is defined as follows:

Proposed resolution (approved by CWG 2024-03-01):

Change in 7.5.5.2 [expr.prim.id.unqual] paragraph 3 as follows:

... [Note 4: If the entity is a template parameter object for a template parameter of type T (13.2 [temp.param]), the type of the expression is const T. end note] In all other cases, the type of the expression is the type of the entity.