Boost logo

Boost :

From: JOAQUIN LOPEZ MU?Z (joaquin_at_[hidden])
Date: 2006-02-17 15:47:36


Hello everybody,

I know the following is not Boost-related, but after
getting zero responses in clc++m and cs++, I don't
really know where else to go to. You might want
to respond privately so as to keep the list clean.
Thank you, and excuse my little abuse.

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


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk