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

2024-11-11


2401. Array decay vs prohibition of subobject non-type arguments

Section: 13.4.3  [temp.arg.nontype]     Status: drafting     Submitter: John Spicer     Date: 2019-02-06

Consider an example like:

  template <const char *N> struct A { static const int val; };

  template <const char *N> const int A<N>::val = 0;

  static const char c[2] = "";

  int main() {
    A<c> a;
    return A<c>::val;
  }

Formally, this appears to violate the prohibition of using the address of a subobject as a non-type template argument, since the array reference c in the argument decays to a pointer to the first element of the array. However, at least some implementations accept this example, and at least conceptually the template argument designates the complete object. Should an exception be made for the result of array decay?

See also issue 2043.

Notes from the July, 2019 meeting

CWG felt that the example should be allowed if the parameter type is a pointer to object type (thus prohibiting void*).