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

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

Messages

Date: 2019-02-06.00:00:00

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?

History
Date User Action Args
2019-02-06 00:00:00admincreate