Title
Type deduction with initializer list containing ambiguous functions
Status
dup
Section
13.10.3.2 [temp.deduct.call]
Submitter
Jonathan Caves

Created on 2016-08-12.00:00:00 last changed 74 months ago

Messages

Date: 2018-02-27.00:00:00

Rationale, July, 2017

This issue is a duplicate of issue 2318.

Date: 2022-11-20.07:54:16

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.

History
Date User Action Args
2018-02-27 00:00:00adminsetmessages: + msg6028
2016-08-12 00:00:00admincreate