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-18


2326. Type deduction with initializer list containing ambiguous functions

Section: 13.10.3.2  [temp.deduct.call]     Status: dup     Submitter: Jonathan Caves     Date: 2016-08-12

Consider the following example:

  template<typename T, int N> void g(T (* const (&)[N])(T)) { }

  int f1(int);
  int f4(int);
  char f4(char);

  void f() {
    g({ &f1, &f4 });  // OK, T deduced to int, N deduced to 2?
  }

There is implementation divergence on the handling of this example. According to 13.10.3.2 [temp.deduct.call] paragraph 1,

If removing references and cv-qualifiers from P gives std::initializer_list<P'> or P'[N] for some P' and N and the argument is a non-empty initializer list (9.4.5 [dcl.init.list]), then deduction is performed instead for each element of the initializer list, taking P' as a function template parameter type and the initializer element as its argument, and in the P'[N] case, if N is a non-type template parameter, N is deduced from the length of the initializer list.

Deduction fails for the &f4 element fails due to ambiguity, so by 13.10.3.6 [temp.deduct.type] bullet 5.5.1 the function parameter is a non-deduced context.

It is not clear, however, whether that implies that the function parameter is a non-deduced context from the perspective of the entire deduction, so we cannot deduct T and N, or if it's only a non-deduced context for this slice of the initializer list deduction and we can still deduce the template parameters from the &f1 element.

See also issue 1513.

Rationale, July, 2017

This issue is a duplicate of issue 2318.