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

2024-09-25


2296. Are default argument instantiation failures in the “immediate context”?

Section: 13.10.3  [temp.deduct]     Status: open     Submitter: Jason Merrill     Date: 2016-06-25     Liaison: EWG

Consider the following example (taken from issue 3 of paper P0348R0):

  template <typename U> void fun(U u = U());

  struct X {
    X(int) {}
  };

  template <class T> decltype(fun<T>()) g(int) { }

  template<> void g(long) { }

  int main() { g<X>(0); }

When is the substitution into the return type done? The current specification makes this example ill-formed because the failure to instantiate the default argument in the decltype operand is not in the immediate context of the substitution, although a plausible argument for making this a SFINAE case can be made.

Notes from the June, 2016 meeting:

CWG decided to refer this question to EWG for their consideration.

EWG 2022-11-11

This is tracked in github issue cplusplus/papers#1377. See also paper P2285 (Are default function arguments in the immediate context?), tracked by github issue cplusplus/papers#976.

CWG 2024-06-28

See also issues 1554 and 1844 for other cases of missing clarity for "immediate context".