Title
More on partial ordering of function templates
Status
open
Section
13.7.7.3 [temp.func.order]
Submitter
Nathan Sidwell

Created on 2003-04-07.00:00:00 last changed 255 months ago

Messages

Date: 2003-10-15.00:00:00

Notes from the October 2003 meeting:

There was some sentiment that it would be desirable to have this case ordered, but we don't think it's worth spending the time to work on it now. If we look at some larger partial ordering changes at some point, we will consider this again.

Date: 2003-04-15.00:00:00

This was split off from issue 214 at the April 2003 meeting.

Nathan Sidwell: John Spicer's proposed resolution does not make the following well-formed.

  template <typename T> int Foo (T const *) {return 1;} //#1
  template <unsigned I> int Foo (char const (&)[I]) {return 2;} //#2

  int main ()
  {
    return Foo ("a") != 2;
  }

Both #1 and #2 can deduce the "a" argument, #1 deduces T as char and #2 deduces I as 2. However, neither is more specialized because the proposed rules do not have any array to pointer decay.

#1 is only deduceable because of the rules in 13.10.3.2 [temp.deduct.call] paragraph 2 that decay array and function type arguments when the template parameter is not a reference. Given that such behaviour happens in deduction, I believe there should be equivalent behaviour during partial ordering. #2 should be resolved as more specialized as #1. The following alteration to the proposed resolution of DR214 will do that.

Insert before,

  • If A is a cv-qualified type, A is replaced by the cv-unqualified version of A.

the following

  • If P was not originally a reference type,
    • If A is an array type, A is replaced by the pointer type produced by the array to pointer conversion
    • If A is a function type, A is replaced by the pointer type produced by the function to pointer conversion

For the example above, this change results in deducing 'T const *' against 'char const *' in one direction (which succeeds), and 'char [I]' against 'T const *' in the other (which fails).

John Spicer: I don't consider this a shortcoming of my proposed wording, as I don't think this is part of the current rules. In other words, the resolution of 214 might make it clearer how this case is handled (i.e., clearer that it is not allowed), but I don't believe it represents a change in the language.

I'm not necessarily opposed to such a change, but I think it should be reviewed by the core group as a related change and not a defect in the proposed resolution to 214.

History
Date User Action Args
2003-11-15 00:00:00adminsetmessages: + msg946
2003-04-07 00:00:00admincreate