Topic: DR 214 Partial ordering 14.5.5.2


Author: deepblue57x@yahoo.co.nz (Graeme Prentice)
Date: Sun, 5 Oct 2003 18:54:42 +0000 (UTC)
Raw View

Hi coders

I have some comments/ questions on defect report 214 Partial ordering of
function templates as found in the Core language active issues 25 April
2003 document.

Near the end of DR 214, there is a block of text starting with a heading
in bold  (temp.deduct.partial)  - my comments relate to this text.


1.  The text uses the term "transformations" for two different things  -
firstly the transformation specified in 14.5.5.2 and secondly for the
dropping of references and top level const.  I think it would be clearer
if the term "adjustments" was used instead of transformations, for the
dropping of references and top level const.  Then we can say ... A is a
type that has both transformation and adjustment applied to it, P is a
type that has adjustment but not transformation applied, and later text
can refer to adjustments instead of transformations.


2.  The text describes firstly that references are dropped and then that
top level CV qualifiers are removed.  It's not clear to me whether T
const & becomes T or const T  i.e. after dropping the reference, are
remaining top level CV quailfiers also dropped.  The text effectively
states that they are, but I believe this should be clarified, especially
since no compiler currently does this AFAIK.


3.  Following the bulleted list describing the removal of CV qualifiers,
there is a sentence that says the following - (angle brackets <>
surround quoted text below  )  ...

<  If, for a given type, deduction succeeds in both directions (i.e.,
the types are identical after the transformations above) if the type
from the argument template is more cv-qualified than the type from the
parameter template (as described above) that type is considered to be
more specialized than the other.  >

The above sentence puzzles me  - firstly it says,   < for a given type,
deduction succeeds in both directions >       - this means that for both
P A pairs, deduction succeeds  - but then it says  ...   < i.e. the
types are identical after the transformations above >     -  which types
are these?
The deduction process deduces template parameter types (and values and
templates) that appear in P by "mapping"  A to it.  14.8.2.4 para 1 says
the deduction process tries to make the deduced A "compatible" with A
(where "deduced A" refers to P after substitution with deduced
"values").

DR 214 appears to say (  < i.e. the types are identical ... > ) that the
deduced A has to be identical to A.  If so, DR 214 should say so
explicitly (as 14.5.5.2 para 4 does) in the preceding paragraph and not
as an "i.e." in the sentence I am currently discussing.  The phrase  <
i.e. the types are identical after the transformations above >  seems
wrong  - what have the "transformations" got to do with A and the
deduced A being identical?

The phrase < as described above > that I quote above, would be clearer
if it tagged the sentence referred to by "as described above" with e.g.
*1  i.e. the text earlier could say < the result of this determination
will be used below *1 >



4.  How are types that don't participate in deduction treated?

The code at the end of this post fails to compile with GCC and Comeau
4.3.3 , both of whom report an ambiguity for the call to f1.  Both
functions are callable and neither has "superior conversion sequences"
for every argument in the call, which means partial ordering is used.
Partial ordering is failing to resolve the ambiguity yet deduction of
(U, float, alpha) into the second f1() succeeds but fails in reverse
because beta can't convert to alpha.

Why does partial ordering fail and how are arguments and parameters that
play no part in deduction of template parameter types treated?  Are
references and top level const dropped as DR 214 says?  Are the
arguments treated as lvalues or rvalues?  Are implicit conversions
allowed?  DR 214 doesn't acknowledge their existence but it seems from
the way current compilers behave, they have to be an exact match or
deduction fails in both directions.  This is not how "normal" argument
deduction works which either ignores them or allows implicit conversions
(14.8.2 doesn't say which) but is implied by 14.5.5.2 para 4.



5.  Do current compilers use the rules in e.g. 14.8.2.1 para 2 for the
dropping of references, top level const and array to pointer conversions
etc. and if so, will these DR 214 changes break a lot of existing code?



6.  How does DR 214 affect the ordering of class partial specializations
which also uses the partial ordering rules?


Graeme


[ If I change the function signatures below to this
template <typename T>
void f1( T, T*, float, alpha )

template <typename T>
void f1( T, int*, double, beta )
then an ambiguity still occurs ]


#include <iostream>

struct alpha
{
    alpha(){}
};

struct beta
{
    beta( alpha ) {}
    beta(){}
};

template <typename T>
void f1( T, float, alpha )
{
    std::cout << "\nf1 alpha";
}

template <typename T>
void f1( T, double, beta )
{
    std::cout << "\nf1 beta";
}

int main()
{
    f1( 44, 45.1, alpha() );
}

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]