Title
Generalized template arguments and array-to-pointer decay
Status
drafting
Section
13.4.3 [temp.arg.nontype]
Submitter
Richard Smith

Created on 2014-11-13.00:00:00 last changed 34 months ago

Messages

Date: 2022-11-25.07:42:21

Suggested resolution:

Change the referenced bullet to read:

  • a subobject (6.7.2 [intro.object]) that is not the first element of a complete object of array type,

Note that this resolution also allows an example like

    template<char &p> struct S { };
    char arr[2];
    S<arr[0]> s_arr;

which may not be exactly what we want.

See also issue 2401.

Date: 2022-02-18.07:47:23

According to 13.4.3 [temp.arg.nontype] paragraph 1 (newly revised by the adoption of paper N4268),

For a non-type template-parameter of reference or pointer type, the value of the constant expression shall not refer to (or for a pointer type, shall not be the address of):

This change breaks an example like

   template<int *p> struct X {};
   int arr[32];
   X<arr> x;

because the array-to-pointer decay produces a pointer to the first element, which is a subobject.

History
Date User Action Args
2022-02-18 07:47:23adminsetmessages: + msg6708
2014-11-13 00:00:00admincreate