Title
Array decay vs prohibition of subobject non-type arguments
Status
drafting
Section
13.4.3 [temp.arg.nontype]
Submitter
John Spicer

Created on 2019-02-06.00:00:00 last changed 25 months ago

Messages

Date: 2019-07-15.00:00:00

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*).

Date: 2022-11-25.07:42:21

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.

History
Date User Action Args
2022-11-25 07:42:21adminsetmessages: + msg7064
2022-11-25 07:42:21adminsetstatus: open -> drafting
2019-02-06 00:00:00admincreate