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

2024-03-20


2497. Points of instantiation for constexpr function templates

Section: 13.8.4.1  [temp.point]     Status: drafting     Submitter: Richard Smith     Date: 2019-07-20

Consider:

  template<typename T> constexpr T f();
  constexpr int g() { return f<int>(); } // #1
  template<typename T> constexpr T f() { return 123; }
  int k[g()];
  // #2

There are two points of instantiation for f<int>. At #1, the template isn't defined, so it cannot be instantiated there. At #2, it's too late, as the definition was needed when parsing the type of k.

Should we also treat the point of definition of (at least) a constexpr function template as a point of instantiation for all specializations that have a point of instantiation before that point? Note the possible interaction of such a resolution with 13.8.4.1 [temp.point] paragraph 7:

If two different points of instantiation give a template specialization different meanings according to the one-definition rule (6.3 [basic.def.odr]), the program is ill-formed, no diagnostic required.

Notes from the November, 2021 teleconference:

Another possibility for a point of instantiation, other than the definition of the template, would be the point at which the function is called. Similar questions have been raised regarding the points at which variables are initialized (issue 2186) and constexpr functions are defined (issue 2166).