Re: function template explicit specialization not chosen
I think you are misinterpreting Comeau here: The compiler does *not*
link (see the corresponding remark somewhere on the web page), and
odr-using a function without definition does not require a
diagnostic. In other words: The fact, that Comeau seemingly accepts
the code does not proof that it selects the second form. In fact,
such behaviour would be very astonishing: The outcome of overload
resolution does not depend on whether a function (template)
definition exists or not.
Ah, great catch. Thanks.
So even though the argument type A is a cv-qualified type (The type
is 'dummy const'), this is irrelevant here. As a rule of thumb one
should remember that a function template that looks like using
"by-value" arguments, will have this way, unless you provide
explicit template parameters that would change that.
May I also ask that b's type is dummy const& and in hash(b) you
directly started talking about A being dummy const (taking off the
reference already), this stripe off of reference for the expression is
supported by 5/5 [expr]
"If an expression initially has the type ?reference to T? (8.3.2,
8.5.3), the type is adjusted to T prior to any further analysis. The
expression designates the object or function denoted by the reference,
and the expression is an lvalue or an xvalue, depending on the
expression."
Given this rule in 5/5. It is also impossible for decltype(b) to be
dummy const& were decltype designed to use the template argument
deduction rules, and that's why in 7.1.6.2/4 [dcl.type.simple],
decltype is given a set of special rule to follow.
Moreover, since auto follows template deduction rules, it means the
following is true.
auto c = b; // c is of type dummy
decltype(b) d = b; // d is of type dummy const&
Am I right in the claims? Thanks again.
I'm not sure that I understand you correctly: There won't happen any
overload resolution between 'int hash(dummy)' and 'int hash(const
dummy&). There does only exist a single function template, the
compiler deduces the parameter types by the process described in
[temp.deduct.call] and this ends in a deduced form of int
hash<dummy>(dummy). There does not exist an explicit specialization
of that form, therefore the primary form is instantiated. This
clearly demonstrates that you would need to provide a specialization
of this form
template <> int hash (dummy) { return 0; }
to get the compiler find the wanted specialization.
Now that I see the process, I understand only the dummy specialization
exists.
I don't see any evidence that both compiler differ here.
Yes, I agree with you.
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]