egcs-ss-970825: template function linking problem
Alexandre Oliva
oliva@dcc.unicamp.br
Tue Sep 2 03:58:00 GMT 1997
Jonathan Larmour writes:
> At 21:14 29/08/97 -0300, Alexandre Oliva wrote:
>> Jonathan Larmour writes:
>>
>>> template <class T> void problem_fn(T &obj);
>>
>>> // printf("%p\n", &problem_fn); // Uncomment this line and it stops
> linking
>> Besides gcc failing to instantiate the template it decided to use,
>> there's no way to find out which template function it should have
>> used, so an error should have been flagged at compile-time.
> Is that true? Remember the linking error I got _did_ have the correct type
What do you mean correct type? Why should it have preferred
problem_fn<int> over problem_fn<void> or
problem_fn<::foo::bar::anytype_at_all*> ? :-)
> which implies gcc knew exactly which type to use
which was wrong.
>> The correct syntax would be to refer to &problem_fn<int>, but we still
>> can't do that in gcc, AFAIK.
> Specifying the type exactly slightly removes the point of templates though!
Not in this case. Given the above declaration of problem_fn, you may
either:
// know in advance which type to instantiate:
void foo() { printf("%p\n", problem_fn<int>); }
// or not:
template <class T>
void bar() { printf("%p\n", problem_fn<T>); }
But the compiler must not be able to guess for you unless it has
enough context to decide. In the example I gave below:
>> void (*f)(int&) = problem_fn;
The compiler is able (and required) to deduce the appropriate type for
problem_fn, so it can guess which specialization you're talking about.
However, in an ellipsis argument such as the one for printf, there's
no context information for the appropriate specialization to be
selected.
> This didn't work either when I tried it :-(. (Or do you mean, if the
> instantiation problem was fixed?).
That's what I meant.
--
Alexandre Oliva
mailto:oliva@dcc.unicamp.br mailto:aoliva@acm.org
Universidade Estadual de Campinas, SP, Brasil
More information about the Gcc-bugs
mailing list