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

2024-04-28


2734. Immediate forward-declared function templates

Section: 7.7  [expr.const]     Status: open     Submitter: Corentin Jabot     Date: 2023-05-10

Consider:

  consteval int a(auto);
  constexpr int g(auto e);
  constexpr int f(auto e);

  constexpr int f(auto e) {
    return a(e);
  }

  auto ff = f<int>;   // error: f is an immediate function

  auto gg = g<int>;   // ok?

  constexpr int g(auto e) { // g is not an immediate function?
    return a(e);
  }

The standard is silent as to what happen if no function body is available at the point where we need to determine whether a constexpr function template is an immediate function template.

Furthermore, there is no wording that taking the address of a constexpr function template specialization instantiates its body to determine whether it is an immediate function, unlike the handling of auto return types.

Subclause 13.9.2 [temp.inst] paragraph 5 specifies:

Unless a function template specialization is a declared specialization, the function template specialization is implicitly instantiated when the specialization is referenced in a context that requires a function definition to exist or if the existence of the definition affects the semantics of the program. ...

See also issue 2497.