Movatterモバイル変換


[0]ホーム

URL:


Issue 2318 - WG21 CWG Issues
Title
Nondeduced contexts in deduction from a braced-init-list
Status
cd5
Section
13.10.3.6 [temp.deduct.type]
Submitter
Jonathan Caves

Created on2016-08-12.00:00:00 last changed62 months ago

Messages

msg6425 (view)
Date: 2018-11-15.00:00:00

Proposed resolution (November, 2018):

Change 13.10.3.2 [temp.deduct.call] paragraph 1 as follows:

Template argument deduction is done by comparing eachfunction template parameter type (call itP) thatcontainstemplate-parameters that participate intemplate argument deduction with the type of thecorresponding argument of the call (call itA) asdescribed below. If removing references and cv-qualifiersfromPgivesstd::initializer_list<P'>orP' [N]for someP" andN andthe argument is a non-empty initializer list(9.5.5 [dcl.init.list]), then deduction is performedinstead for each element of the initializerlistindependently, takingP' asaseparate function template parametertypesP'iand thei-thinitializer element asitsthe correspondingargument., and inIn theP' [N] case,ifN is a non-type template parameter,Nis deduced from the length of the initializerlist. Otherwise, an initializer list argument causes theparameter to be considered a non-deduced context(13.10.3.6 [temp.deduct.type]). [Example:

  ...  template<class T, int N> void n(T const(&)[N], T);  n({{1},{2},{3}},Aggr()); // OK,T isAggr,N is3  template<typename T, int N> void o(T (* const (&)[N])(T)) { }  int f1(int);  int f4(int);  char f4(char);  o({ &f1, &f4 }); // OK,T deduced asint from first element, nothing deduced from second element,N deduced as2  o({ &f1, static_cast<char(*)(char)>(&f4) }); // error: conflicting deductions forT
msg5920 (view)
Date: 2017-07-15.00:00:00

Notes from the July, 2017 meeting:

CWG determined that the call is well-formed.

msg5919 (view)
Date: 2019-02-15.00:00:00

[Accepted as a DR at the February, 2019 meeting.]

The status of an example like the following is unclear:

  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 toint,N deduced to2?  }

The problem is the interpretation of 13.10.3.6 [temp.deduct.type] paragraph 4:

In most cases, the types, templates, and non-type values that are used tocomposeP participate in template argument deduction. That is,they may be used to determine the value of a template argument, and thevalue so determined must be consistent with the values determinedelsewhere. In certain contexts, however, the value does not participate intype deduction, but instead uses the values of template arguments that wereeither deduced elsewhere or explicitly specified. If a template parameteris used only in non-deduced contexts and is not explicitly specified,template argument deduction fails.

According to 13.10.3.2 [temp.deduct.call] paragraph 1, deduction isperformed independently for each element of the initializer list:

Template argument deduction is done by comparing each function templateparameter type (call itP) thatcontainstemplate-parameters that participate in template argumentdeduction with the type of the corresponding argument of the call (call itA) as described below. If removing references and cv-qualifiersfromP givesstd::initializer_list<P'>orP'[[N] for someP' andN and the argument is anon-empty initializer list (9.5.5 [dcl.init.list]), then deduction isperformed instead for each element of the initializer list,takingP' as a function template parameter type and theinitializer element as its argument, and in theP'[N] case,ifN is a non-type template parameter,N is deduced fromthe length of the initializer list. Otherwise, an initializer list argumentcauses the parameter to be considered a non-deduced context(13.10.3.6 [temp.deduct.type]).

Deduction fails for the second element of the list,&f4,because of ambiguity. Does this mean that deduction fails for the entirecall, or does the successful deduction ofT from the firstelement andN from the length of the list result in successfuldeduction for the call?

History
DateUserActionArgs
2020-12-15 00:00:00adminsetmessages: +msg6425
2020-12-15 00:00:00adminsetstatus: drafting -> cd5
2018-02-27 00:00:00adminsetmessages: +msg5920
2016-08-12 00:00:00admincreate

[8]ページ先頭

©2009-2026 Movatter.jp