Joaquín M López Muñoz Guest
|
Posted: Tue Feb 14, 2006 1:06 am Post subject: Doubt about std 14.6.4.2 |
|
|
[I'm reposting here after some days without getting response
from comp.std.c++]
Consider the following snippet:
template<typename T>
static void foo(T){}
template<typename T>
void bar(T t)
{
foo(t);
}
int main()
{
bar(0);
}
This is illegal because of std 14.6.4.2, which states that
"For a function call that depends on a template parameter, if the
function name is an unqualified-id but not a template-id, the
candidate functions are found using the usual lookup rules
(basic.lookup.unqual, basic.lookup.koenig) except that:
[internal linkage function excluded from lookup]"
So far so good, I know the rationale behind exclusion of internal
linkage functions as a way to fight ODR violations. But consider
now the following, slightly different code:
template<typename T>
static void foo(){}
template<typename T>
void bar(T t)
{
foo<T>();
}
int main()
{
bar(0);
}
Seems like this must be also illegal for the same reasons as
before, and in fact Comeau Online says so, but a closer reading
of 14.6.4.2 reveals (emphasis mine):
"For a function call that depends on a template parameter, if the
function name is an unqualified-id ***but not a template-id***,..."
And, in the second snippet, foo is called thru the template-id
foo<T>!! So my questions are:
1. Am I right in thinking that 14.6.4.2 explicitly does not apply
to the second snippet where the unqualified call is a
template-id?
2. If so, what's the rationale? The same ODR problems occur here.
I guess I must be making some gross mistake here, but can't figure
it out.
Thank you,
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ] |
|