c++/3423: "iterator" name lookup trouble
Artem Khodush
artem@duma.gov.ru
Tue Jun 26 06:01:00 GMT 2001
> #include <vector>
> -------------------------------------------------------------------------------
> using namespace std;
>
> template <class T>
> struct coord_vector {
> };
>
> template<class T>
> struct polygon_segment : public vector<coord_vector<T> > {
> void insert_c(iterator it);
> };
>
> -------------------------------------------------------------------------------
> This file results in a parse error in the "insert_c" line, though
> it should probably find the superclass's iterator.
No it shouldn't, since the unqualified name 'iterator' does not
depend on the template parameter, and according to the
c++ standard, is looked up elsewhere but the base class.
14.6 - Name resolution
-9- If a name does not depend on a template-parameter (as
defined in temp.dep), a declaration (or set of declarations)
for that name shall be in scope at the point where the name
appears in the template definition; the name is bound to the
declaration (or declarations) found at that point and this
binding is not affected by declarations that are visible at the
point of instantiation.
14.6.2 - Dependent names
-3- In the definition of a class template, ... if a base class
of this template depends on a template-parameter, the base
class scope is not examined during name lookup until the
class template is instantiated.
So the only solution is to fix the code to make iterator
dependent on the template parameter, as you've
mentioned:
> >Fix:
> qualify "iterator" with superclass name
More information about the Gcc-bugs
mailing list