Title
Points of instantiation for constexpr function templates
Status
drafting
Section
13.8.4.1 [temp.point]
Submitter
Richard Smith

Created on 2019-07-20.00:00:00 last changed 37 months ago

Messages

Date: 2021-11-15.00:00:00

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

Date: 2022-09-25.18:08:42

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.
History
Date User Action Args
2021-11-15 00:00:00adminsetmessages: + msg6546
2019-07-20 00:00:00admincreate