Title
Deducing function types from cv-qualified types
Status
drafting
Section
13.10.3.2 [temp.deduct.call]
Submitter
Daniel Krügler

Created on 2012-11-04.00:00:00 last changed 108 months ago

Messages

Date: 2015-05-15.00:00:00

Notes from the May, 2015 meeting:

The consensus of CWG was that the cv-qualification of the argument and parameter must match, so the original example should be rejected.

Date: 2014-11-24.00:00:00

Additional note, November, 2014:

Concern was expressed regarding the proposed resolution over its treatment of an example like the following:

  template<typename T> struct tuple_size {};
  template<typename T> struct tuple_size<T const>: tuple_size<T> {};

  tuple_size<void()> t;

In this case T const is always considered to be more specialized for void(), leading to infinite self-derivation.

The issue has been returned to "open" status for further consideration.

Date: 2013-04-15.00:00:00

Proposed resolution (April, 2013):

Change 13.10.3.6 [temp.deduct.type] paragraph 18 as follows:

A template-argument can be deduced from a function, pointer to function, or pointer to member function type. [Note: cv-qualification of a deduced function type is ignored; see 9.3.4.6 [dcl.fct]. —end note] [Example:

  template<class T> void f(void(*)(T,int));
  template<class T> void f2(const T*);
  template<class T> void foo(T,int);
  void g(int,int);
  void g(char,int);
  void g2();

  void h(int,int,int);
  void h(char,int);
  int m() {
    f(&g);     // error: ambiguous
    f(&h);     // OK: void h(char,int) is a unique match
    f(&foo);   // error: type deduction fails because foo is a template
    f2(g2);    // OK: cv-qualification of deduced function type ignored
  }

end example]

Date: 2012-11-04.00:00:00

It is not clear whether the following is well-formed or not:

  void foo(){}

  template<class T>
  void deduce(const T*) { }

  int main() {
    deduce(foo);
  }

Implementations vary in their treatment of this example.

History
Date User Action Args
2015-05-25 00:00:00adminsetmessages: + msg5533
2015-05-25 00:00:00adminsetstatus: open -> drafting
2014-11-24 00:00:00adminsetmessages: + msg5256
2014-11-24 00:00:00adminsetstatus: ready -> open
2014-03-03 00:00:00adminsetstatus: review -> ready
2013-05-03 00:00:00adminsetmessages: + msg4323
2013-05-03 00:00:00adminsetstatus: open -> review
2012-11-04 00:00:00admincreate