This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: template operator instantiation problem (istream_iterator)


Yotam Medini writes:

> It seems that the operator
>   " istream_iterator ==  istream_iterator "
> has instantiation problems.

It doesn't.  It is just not defined anywhere.  The error has became
visible since egcs stopped accepting guiding declarations, as the one
in line 697 of iterator.h.  A friend declaration that refers to the
appropriate template member function would require template brackets
after the function name, i.e., the declaration would have to be:

friend bool operator==<>( //...

Explicit instantiation also requires template brackets, however it
seems that egcs does not perform that check.


I've been re-reading the template section of CD2, but I was unable to
find out exactly which version of operator== should be selected.

First of all, the most specialized version should be selected, so the
template defined in line 750 should be used, even if it is declared
after the friend declaration.

Even if I change the friend declaration so that an explicit template
specialization is referred to, the most specialized version of the
template is selected.  That is, even if I write:

friend bool operator==<istream_iterator<T, Distance> >( //...

(which is the only declared version of operator== at that point)

the other template version is used.  This seems correct, since, when
the template is implicitly instantiated, both declarations are
visible.  However, only the first one is declared to be a friend of
the iterator class, so the implicit instantiation of the template
should fail due to restricted access.

The attached code snippet should make my points clearer...

-- 
Alexandre Oliva
mailto:oliva@dcc.unicamp.br mailto:aoliva@acm.org
http://www.dcc.unicamp.br/~oliva
Universidade Estadual de Campinas, SP, Brasil

test.cc


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]