Topic: Doubt about std 14.6.4.2


Author: "=?iso-8859-1?B?Sm9hcXXtbiBNIEzzcGV6IE118W96?=" <joaquin@tid.es>
Date: Fri, 10 Feb 2006 10:05:32 CST
Raw View
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


---
[ 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                       ]