Type of id-expression denoting a template parameter object
13.2 [temp.param]
Jim X

Created on 2023-07-26.00:00:00 last changed 1 month ago


Date: 2023-07-26.00:00:00

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 [dcl.type.decltype] paragraph 1:

For an expression E, the type denoted by decltype(E) is defined as follows:
  • ...
  • otherwise, if E is an unparenthesized id-expression naming a non-type template-parameter (13.2 [temp.param]), decltype(E) is the type of the template-parameter after performing any necessary type deduction ( [dcl.spec.auto], [dcl.type.class.deduct]);
  • ...

Possible resolution:

Change in [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 case, the type of the expression is the type of the entity.
Date User Action Args
2023-07-26 00:00:00admincreate