Title
Immediate forward-declared function templates
Status
open
Section
7.7 [expr.const]
Submitter
Corentin Jabot

Created on 2023-05-10.00:00:00 last changed 11 months ago

Messages

Date: 2023-05-25.22:29:04

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.

History
Date User Action Args
2023-05-10 00:00:00admincreate