------- Comment #14 from mmitchel at gcc dot gnu dot org  2006-01-28 04:13 
-------
For the code in Comment #4, there are two questions:

1. Which of the three template functions is called by main?

2. Which of the three template functions is specialized by the explicit
specialization?

The type of the string literals is "const char*".  So, the call matches all
three templates, with { T : char }, { T : const char }, and { T1 : char, T2 :
char}, respectively.  Since the argument types are "const char*" in all cases,
overload resolution selects the most specialized of the three templates.  The
first template is more specialized than the second, since the first template
can be generated from the second with { T : const T}, but the second cannot be
generated from the first.  The first template is also more specialized than the
third, since it can be generated from the first with { T1 : T, T2 : T }.  Thus,
it is the first template that is called.

Because explicit specializations also specialized the most specialized
template, the answer to the second question is the same; it is the first
template which is specialized.

Therefore, the correct value is indeed 4.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=25855

Reply via email to